CmdID / PowerShell / Cmdlets / Send
Send-MailMessage
Sends an email message. PowerShell reference
From the PowerShell reference 15 parameters
What it does
Sends an email message. The Send-MailMessage cmdlet sends an email message from within PowerShell. You must specify a Simple Mail Transfer Protocol (SMTP) server or the Send-MailMessage command fails. Use the SmtpServer parameter or set the $PSEmailServer variable to a valid SMTP server. The value assigned to $PSEmailServer is the default SMTP setting for PowerShell. For more information, see about_Preference_Variables. WARNING: The Send-MailMessage cmdlet is obsolete. This cmdlet doesn't guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage. For more information, see Platform Compatibility note DE0005.
Send-MailMessage [-To] <string[]> [-Subject] <string> [[-Body] <string>] [[-SmtpServer] <string>] -From <string> [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Encoding <Encoding>] [-Cc <string[]>] [-DeliveryNotificationOption <DeliveryNotificationOptions>] [-Priority <MailPriority>] [-Credential <pscredential>] [-UseSsl] [-Port <int>] [<CommonParameters>]
Send an email from one person to another person
$sendMailMessageSplat = @{
From = 'User01 <user01@fabrikam.com>'
To = 'User02 <user02@fabrikam.com>'
Subject = 'Test mail'
}
Send-MailMessage @sendMailMessageSplatIdentifySend an attachment
$sendMailMessageSplat = @{
From = 'User01 <user01@fabrikam.com>'
To = 'User02 <user02@fabrikam.com>', 'User03 <user03@fabrikam.com>'
Subject = 'Sending the Attachment'
Body = "Forgot to send the attachment. Sending now."
Attachments = '.\data.csv'
Priority = 'High'
DeliveryNotificationOption = 'OnSuccess', 'OnFailure'
SmtpServer = 'smtp.fabrikam.com'
}
Send-MailMessage @sendMailMessageSplatIdentifySend email to a mailing list
$sendMailMessageSplat = @{
From = 'User01 <user01@fabrikam.com>'
To = 'ITGroup <itdept@fabrikam.com>'
Cc = 'User02 <user02@fabrikam.com>'
Bcc = 'ITMgr <itmgr@fabrikam.com>'
Subject = "Don't forget today's meeting!"
Credential = 'domain01\admin01'
UseSsl = $true
}
Send-MailMessage @sendMailMessageSplatIdentifyIts page in the reference: Send-MailMessage.
Parameters
-AttachmentsSpecifies the path and file names of files to be attached to the email message. You can use this parameter or pipe the paths and file names to Send-MailMessage.-BccSpecifies the email addresses that receive a copy of the mail but aren't listed as recipients of the message. Enter names (optional) and the email address, such as Name <someone@fabrikam.com>.-BodySpecifies the content of the email message.-BodyAsHtmlSpecifies that the value of the Body parameter contains HTML.-CcSpecifies the 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@fabrikam.com>.-CredentialSpecifies a user account that has permission to perform this action. The default is the current user.
Credentials are stored in a PSCredential object and the password is stored as a SecureString.
NOTE: For more information about SecureString data protection, see How secure is SecureString?.-DeliveryNotificationOptionSpecifies the delivery notification options for the email message. You can specify multiple values. None is the default value. The alias for this parameter is DNO.
The delivery notifications are sent to the address in the From parameter.
The acceptable values for this parameter are as follows:
- 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.
These values are defined as a flag-based enumeration. You can combine multiple values together to set multiple flags using this parameter. The values can be passed to the DeliveryNotification parameter as an array of values or as a comma-separated string of those values. The cmdlet will combine the values using a binary-OR operation. Passing values as an array is the simplest option and also allows you to use tab-completion on the values.-EncodingSpecifies the type of encoding for the target file. The default value is Default.
The acceptable values for this parameter are as follows:
- ASCII Uses ASCII (7-bit) character set.
- BigEndianUnicode Uses UTF-16 with the big-endian byte order.
- Default Uses the encoding that corresponds to the system's active code page (usually ANSI).
- OEM Uses the encoding that corresponds to the system's current OEM code page.
- Unicode Uses UTF-16 with the little-endian byte order.
- UTF7 Uses UTF-7.
- UTF8 Uses UTF-8.
- UTF32 Uses UTF-32 with the little-endian byte order.-FromThe From parameter is required. This parameter specifies the sender's email address. Enter a name (optional) and email address, such as Name <someone@fabrikam.com>.-PortSpecifies an alternate port on the SMTP server. The default value is 25, which is the default SMTP port.-PrioritySpecifies the priority of the email message. Normal is the default. The acceptable values for this parameter are Normal, High, and Low.-SmtpServerSpecifies 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 isn't set and this parameter isn't used, the Send-MailMessage command fails.-SubjectThe Subject parameter isn't required. This parameter specifies the subject of the email message.-ToThe To parameter is required. This parameter specifies the recipient's email address. Enter names (optional) and the email address, such as Name <someone@fabrikam.com>.-UseSslThe Secure Sockets Layer (SSL) protocol is used to establish a secure connection to the remote computer to send mail. By default, SSL isn't used.