Posts Tagged SMTP

Setting SMTP Message Priority in Powershell


To expand on my previous post regarding how to send email from Powershell, below is an example that includes forcing plain text (or html), setting mesage priority, setting notification options, as well as adding CC: and BCC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Setting SMTP Priority using Powershell V1
# Yattaa.com 10/07/2009
#
$email = New-Object System.Net.Mail.MailMessage
$email.From = "user@yourdomain.com"
$email.To.Add("user@yourdomain.com")
$email.To.Add("user@yourdomain.com")
$email.CC.Add("user@yourdomain.com")
$email.BCC.Add("user@yourdomain.com")
$email.DeliveryNotificationOptions = [System.Net.Mail.DeliveryNotificationOptions]::OnSuccess
$email.IsBodyHtml = $false
$email.Priority = [System.Net.Mail.MailPriority]::High
$email.Subject = "Subect Here"
$email.Body = "Body Here"
$smtp = New-Object System.Net.Mail.SmtpClient
$smtp.Host = "SMTP Server Here"
$smtp.Send($email)

, ,

No Comments

sending email in powershell

Version 1:

$emailFrom = “user@domain.com”
$emailTo = “user@domain.com”
$subject = “subject”
$body = “body”
$smtpServer = “smtp server”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

Version 2:

PS C:\Windows\system32> get-help send-mailmessage

NAME
    Send-MailMessage

SYNOPSIS
    Sends an e-mail message.
SYNTAX
    Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]
DESCRIPTION
    The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.
RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135256

REMARKS
    To see the examples, type: “get-help Send-MailMessage -examples”.
    For more information, type: “get-help Send-MailMessage -detailed”.
    For technical information, type: “get-help Send-MailMessage -full”.

, ,

No Comments