Send an email message.

      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]

   -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 <>"

   -Body string
       The body (content) of the email message.

       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 <>".

   -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.

       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".


          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 <>". 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 <>". Required.

       Use the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer 
       to send mail. By default, SSL is not used.

Under Windows, send-mailmessage will create ASCII output by default.
This can be configured via the -Encoding option or by setting the $PSDefaultParameterValues preference variable.
Under PowerShell Core edition, the encoding defaults to BOM-less UTF-8


Send an email (with no body) from User01 to User02:

PS C:\> send-mailmessage -to "User01 <>" -from "User02 <>" -subject "Test mail"

Send an email with an attachment to two users and BCC another:

PS C:\> send-mailmessage -from "" -to "", "" -bcc -subject "Hello World" -body "See attachment below." -Attachment "data.csv" -smtpServer

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):

PS C:\> send-mailmessage -to "ITGroup <>" -from "User01 <>" -cc "User02 <>" -bcc ITMgr <> -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= target=""_blank"">here</a> to open google <br>"
 send-mailmessage "Test email" -bodyashtml -body $body -from -SmtpServer

“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

Copyright © 1999-2021
Some rights reserved