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.

PARAMETERS
    -Attachments <string[]>
        Specifies the path and file names of files to be attached to the e-mail message. You can use this parameter or pipe the paths and file names to Send-MailMessage.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Bcc <string[]>
        Specifies the e-mail addresses that receive a copy of the mail but are not listed as recipients of the message. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Body <string>
        Specifies the body (content) of the e-mail message.

        Required?                    false
        Position?                    3
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -BodyAsHtml [<SwitchParameter>]
        Indicates that the value of the Body parameter contains HTML.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Cc <string[]>
        Specifies the e-mail addresses to which a carbon copy (CC) of the e-mail message is sent. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”. Or, enter a PSCredential object, such as one from the Get-Credential cmdlet.

        Required?                    false
        Position?                    named
        Default value                Current user
        Accept pipeline input?     false
        Accept wildcard characters? false

    -DeliveryNotificationOption <DeliveryNotificationOptions>
        Specifies the delivery notification options for the e-mail message. You can specify multiple values. “None” is the default value. The Alias for this parameter is “dno”.

        The delivery notifications are sent in an e-mail message to the address specified in the value of the To parameter.

        Valid values are:

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

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <Encoding>
        Specifies the encoding used for the body and subject. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, and OEM. ASCII is the default.

        Required?                    false
        Position?                    named
        Default value                ASCII
        Accept pipeline input?     false
        Accept wildcard characters? false

    -From <string>
        Specifies the address from which the mail is sent. Enter a name (optional) and e-mail address, such as “Name <someone@example.com>”. This parameter is required.

        Required?                    true
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Priority <MailPriority>
        Specifies the priority of the e-mail message. The valid values for this are Normal, High, and Low. Normal is the default.

        Required?                    false
        Position?                    named
        Default value                Normal.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -SmtpServer <string>
        Specifies the name of the SMTP server that sends the e-mail 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.

        Required?                    false
        Position?                    4
        Default value                $PSEmailServer
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Subject <string>
        Specifies the subject of the e-mail message. This parameter is required.

        Required?                    true
        Position?                    2
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -To <string[]>
        Specifies the addresses to which the mail is sent. Enter names (optional) and the e-mail address, such as “Name <someone@example.com>”. This parameter is required.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -UseSsl [<SwitchParameter>]
        Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By default, SSL is not used.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe the path and file names of attachments to Send-MailMessage.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Send-MailMessage -To “User01 <user01@example.com>” -From “User02 <user02@example.com>” -Subject “Test mail”

    Description
    ———–
    This command sends an e-mail message from User01 to User02.

    The mail message has a subject, which is required, but it does not have a body, which is optional. Also, because the SmtpServer parameter is not specified, Send-MailMessage uses the value of the $PSEmailServer preference Variable for the SMTP server.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Send-MailMessage -From “User01 <user01@example.com>” -To “User02 <user02@example.com>”, “User03 <user03@example.com>” -Subject “Sending the Attachment” -Body “Forgot to send the attachment. Sending now.” -Attachment “data.csv” -Priority High -dno onSuccess, onFailure -SmtpServer smtp.fabrikam.com

    Description
    ———–
    This command sends an e-mail message with an attachment from User01 to two other users.

    It specifies a priority value of “High” and requests a delivery notification by e-mail when the e-mail messages are delivered or when they fail.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Send-MailMessage -To “User01 <user01@example.com>” -From “ITGroup <itdept@example.com>” -Cc “User02 <user02@example.com>” -Bcc ITMgr <itmgr@example.com> -Subject “Don’t forget today’s meeting!” -Credential domain01\admin01 -UseSsl

    Description
    ———–
    This command sends an e-mail 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).

    The command uses the credentials of a domain administrator and the UseSSL parameter.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135256