Send-MailMessage

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.
       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 a high priority email with an attachment from User01 to two other users:

C:\PS> send-mailmessage -from "User01 <user01@example.com>" -to "User02 <user02@example.com>", "User03 <user03@examp
le.com>" -subject "Sending the Attachment" -body "Forgot to send the attachment. Sending now." -Attachment "data.cs
v" -priority High -dno onSuccess, onFailure -smtpServer smtp.fabrikam.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 email message containing unicode characters:

Send-MailMessage -subject "Föreign chäräcters" -Body 'voilà hêre is yöur messãge' -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -Encoding UTF8

“Learning music by reading about it is like making love by mail” ~ Luciano Pavarotti

Related:

Out-Printer - Send the output to a printer


© Copyright SS64.com 1999-2013
Some rights reserved