Powershell电子邮件:如何发送具有高重要性的电子邮件?

时间:2015-11-17 07:40:40

标签: email powershell

我正在尝试使用Powershell发送具有高重要性的电子邮件。但是当邮件进入收件箱时,它并没有标记为高重要性。

以下是电子邮件脚本:

$EmailFrom = "monitoring@mydomainname.no"
$EmailTo = "fatherazrael@tcs.com"
$Subject = "Disk Space Low: $server"

$Body = "Server Name:  $server, <NEED NEW LINE> Drive: C,  <NEED NEW LINE>  Total Size: $sizeGB,  <NEED NEW LINE> Space Left: $freeSpaceGB"

$SMTPServer = "scan.opinergo.fn"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
#$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("<From mail ID>", "Password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)   

对于高重要性我已经添加了以下内容,但是当邮件来到outlook时没有一个正常工作:

1)$EmailPriority = [System.Net.Mail.MailPriority]::High

邮件来了但不重要

2)$Priority = [System.Net.Mail.MailPriority]::High

邮件来了但不重要

3)$Priority = "high"

邮件来了但不重要

4)$EmailPriority = "high"

邮件来了但不重要

3 个答案:

答案 0 :(得分:8)

此代码会发送一封优先级高的电子邮件:

1

答案 1 :(得分:2)

尝试使用Send-MailMessage cmdlet并指定-Priority参数:

$password = "pass" | ConvertTo-SecureString -AsPlainText -Force
$credentials = New-Object PSCredential("username", $password)

Send-MailMessage `
    -To recipient@example.com `
    -From sender@example.com `
    -Subject Example `
    -SmtpServer smtp.example.com `
    -Credential $credentials
    -Priority High

答案 2 :(得分:1)

$ emailMessage.Priority = 2

$emailSmtpServer = “xyz”
$emailSmtpServerPort = “587”
$emailSmtpUser = “x@y.z”
$emailSmtpPass = “abc”

$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = “x@y.z”
$emailMessage.To.Add( “x1@y.z” )
$emailMessage.To.Add( “x2@y.z” )
$emailMessage.Subject = “EMAIL CHECK!”
$emailMessage.IsBodyHtml = “True”

#Low Priority
#$emailMessage.Priority = 1

#High Priority
$emailMessage.Priority = 2

$emailMessage.Body = @”
    Email body... <br />
    <br />
    <br />
    Message Sent from Power Shell.
“@

$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );

$SMTPClient.Send($emailMessage )