Send-MailMessage -From This email address is being protected from spambots. You need JavaScript enabled to view it. -To "This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it." -Subject "Test Email Subject" -body "This is a test email" -SmtpServer smtpserver.domain.com

 

 

 


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>] [-DeliveryNot
    ificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | H
    igh}] [-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.

    -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 <This email address is being protected from spambots. You need JavaScript enabled to view it.>".

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

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

    -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 <This email address is being protected from spambots. You need JavaScript enabled to view it.>".

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

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

        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.

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

    -From <string>
        Specifies the address from which the mail is sent. Enter a name (optional) and e-mail address, such as "Name <s
        This email address is being protected from spambots. You need JavaScript enabled to view it.>". This parameter is required.

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

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

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

    -To <string[]>
        Specifies the addresses to which the mail is sent. Enter names (optional) and the e-mail address, such as "Name
         <This email address is being protected from spambots. You need JavaScript enabled to view it.>". This parameter is required.

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

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        "get-help about_commonparameters".

    -------------------------- EXAMPLE 1 --------------------------

    C:\PS>send-mailmessage -to "User01 <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -from "User02 <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -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 th
    e 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 <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -to "User02 <This email address is being protected from spambots. You need JavaScript enabled to view it.>", "User03 <[email protected]
    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

    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 <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -from "ITGroup <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -cc "User02 <[email protected]
    xample.com>" -bcc ITMgr <This email address is being protected from spambots. You need JavaScript enabled to view it.> -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.

 


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

 

 


 

Share this blog post on social media:

Social Links

Disclaimer

All advice, installation/configuration how to guides, troubleshooting and other information on this website are provided as-is with no warranty or guarantee. Whilst the information provided is correct to the best of my knowledge, I am not reponsible for any issues that may arise using this information, and you do so at your own risk. As always before performing anything; check, double check, test and always ensure you have a backup.

Copyright ©2016 Andy Barnes - Please do not copy any content including images without prior consent!

Designed and Hosted by Andy Barnes