Send-MailMessage
Published: February 29, 2012
Updated: August 15, 2012
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0
Send-MailMessage
Syntax
Parameter Set: Default Send-MailMessage [-To] <String[]> [-Subject] <String> [[-Body] <String> ] [[-SmtpServer] <String> ] -From <String> [-Attachments <String[]> ] [-Bcc <String[]> ] [-BodyAsHtml] [-Cc <String[]> ] [-Credential <PSCredential> ] [-DeliveryNotificationOption <DeliveryNotificationOptions> ] [-Encoding <Encoding> ] [-Port <Int32> ] [-Priority <MailPriority> ] [-UseSsl] [ <CommonParameters>]
Detailed 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.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
none |
|
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>".
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
3 |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-BodyAsHtml
Indicates that the value of the Body parameter contains HTML.
|
Aliases |
none |
|
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>".
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
named |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-Port<Int32>
Specifies an alternate port on the SMTP server. The default value is 25, which is the default SMTP port.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
named |
|
Default Value |
25 |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
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.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-UseSsl
Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By default, SSL is not used.
|
Aliases |
none |
|
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, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
System.String
You can pipe the path and file names of attachments to Send-MailMessage.
Outputs
The output type is the type of the objects that the cmdlet emits.
-
None
This cmdlet does not generate any output.
Examples
-------------------------- EXAMPLE 1 --------------------------
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.
PS C:\> send-mailmessage -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -subject "Test mail"
-------------------------- EXAMPLE 2 --------------------------
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.
PS C:\> 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." -Attachments "data.csv" -priority High -dno onSuccess, onFailure -smtpServer smtp.fabrikam.com
-------------------------- EXAMPLE 3 --------------------------
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.
PS C:\> 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