简体   繁体   English

使用正则表达式验证Powershell中的电子邮件地址

[英]Using regex to validate email address in powershell

So i made a script that parses a .msg file in outlook and ommits the result. 因此,我制作了一个脚本,可以在Outlook中解析.msg文件并忽略结果。 The whole scripts works except for when I receive an email from inside the network (we use Active Directory) is when i get a result similar to this: /O=Business/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=MIKEF otherwise for emails outside the network I get email@email.com. 整个脚本有效,除了当我收到来自网络内部的电子邮件(我们使用Active Directory)时,或者当我得到类似以下结果时:/ O = Business / OU = FIRST ADMINISTRATIVE GROUP / CN = RECIPIENTS / CN = MIKEF否则对于网络外部的电子邮件,我的电子邮件为email@email.com。 I would like to to validate this this with regex that way it would take the name in the CN=" " and adds it to my @email.com 我想用正则表达式来验证这一点,即使用CN =“”中的名称并将其添加到我的@ email.com中。

$MSGFILEPATH = '\\srv01\FTP\EmailtoSupportPortal\Testing'
$MSGCOMPLETED= '\\srv01\FTP\EmailtoSupportPortal\Testing\Completed'
Function MSGFiles {
Get-ChildItem $MSGFILEPATH -Filter *.msg|`
ForEach-Object{
    $outlook = New-Object -comobject outlook.application
    $msg = $outlook.CreateItemFromTemplate($_.FullName)
    $body = $msg.Body
    $SEM = $msg.SenderEmailAddress
    $Subject = $msg.Subject 
    $SEM
    }
}
MSGFiles

Check the MailItem.SenderEmailType property. 检查MailItem.SenderEmailType属性。 If it is "EX", use MailItem.Sender.GetExchangeUser.PrimarySmtpAddress (be prepared to handle nulls/errors). 如果它是“ EX”,请使用MailItem.Sender.GetExchangeUser.PrimarySmtpAddress(准备处理null /错误)。 Otherwise use the SenderEmailAddress property the way you do that now. 否则,请按现在的方式使用SenderEmailAddress属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM