Send an email message.
Syntax Send-MailMessage [-To] string[] [-Subject] string -From string [[-Body] string] [[-SmtpServer] string] [-Attachments string[]] [-Bcc string[]] [-Cc string[]] [-BodyAsHtml] [-Credential PSCredential] [-DeliveryNotificationOption NotifyOptions] [-Encoding Encoding] [-Priority {Normal | Low | High}] [-UseSsl] [CommonParameters] Key -Attachments string[] The path and file names of files to be attached to the email message. Use this parameter or pipe the path/file names. -Bcc string[] Email addresses that receive a copy of the mail but are not listed as recipients of the message. Enter names (optional) and the email address, such as "Name <someone@example.com>" -Body string The body (content) of the email message. -BodyAsHtml Indicates that the value of the Body parameter contains HTML. -Cc string[] Email addresses to which a carbon copy (CC) of the email message is sent. Enter names (optional) and the email address, such as "Name <someone@example.com>". -Credential PSCredential A user account that has permission to perform this action. The default is the current user. Type a user name, such as "User64" or "Domain64\User64". Or, enter a PSCredential object, such as one from the Get-Credential cmdlet. -DeliveryNotificationOption Delivery notifications (if accepted by the recipient) will be passed back to the email address specified in the -From parameter. The alias for this parameter is "-dno". NotifyOptions: None No notification. OnSuccess Notify if the delivery is successful. OnFailure Notify if the delivery is unsuccessful. Delay Notify if the delivery is delayed. Never Never notify. -Encoding Encoding The encoding used for the body and subject. 'unicode' will send UTF16. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, and OEM. -From string The address from which the mail is sent. Enter a name (optional) and email address, such as "Name <someone@example.com>". This parameter is required. -Priority MailPriority The priority of the email message. The valid values for this are Normal, High, and Low. -SmtpServer string The name of the SMTP server that sends the email message. The default value is the value of the $PSEmailServer preference variable. If the preference variable is not set and this parameter is omitted, the command fails. -Subject string The subject of the email message. This parameter is required. -To string[] The addresses to which the mail is sent. Enter names (optional) and the email address, such as "Name <someone@example.com>". Required. -UseSsl Use the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By default, SSL is not used. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Examples
Send an email (with no body) from User01 to User02:
C:\PS> send-mailmessage -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -subject "Test mail"
Send an email with an attachment to two users and BCC another:
C:\PS> send-mailmessage -from "me@example.com" -to "user01@example.com", "user02@example.com" -bcc helpdesk@example.com -subject "Hello World" -body "See attachment below." -Attachment "data.csv" -smtpServer smtp.example.com
Send an email message from User01 to the ITGroup mailing list with a copy (CC) to User02 and a blind carbon copy (BCC) to the IT manager (ITMgr).:
C:\PS> send-mailmessage -to "ITGroup <itdept@example.com>" -from "User01 <user01@example.com>" -cc "User02 <user02@example.com>" -bcc ITMgr <itmgr@example.com> -subject "Don't forget today's meeting!" -credential domain64\admin01 -useSSL
Send an HTML email:
$body = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
$body += "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: TAHOMA; color: #000000""><P>"
$body += "Dear <b><font color=red>customer</b></font><br>"
$body += "This is an <b>HTML</b> email<br>"
$body += "Click <a href=http://www.google.com target=""_blank"">here</a> to open google <br>"
send-mailmessage user01@example.com "Test email" -bodyashtml -body $body -from me@example.com -SmtpServer smtp.example.com
“Learning music by reading about it is like making love by mail” ~ Luciano Pavarotti
Related PowerShell Cmdlets:
Out-Printer - Send the output to a printer