Send-MailMessage (Microsoft.PowerShell.Utility) – PowerShell | Microsoft Learn

syntax

description

send-mailmessage cmdlet sends an email message from 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.

examples

example 1: send an email from one person to another person

This example sends an email message from one person to another person.

The from, to and subject parameters are required by send-mailmessage. this example uses the default variable $psemailserver for the smtp server, so the smtpserver parameter is not needed.

The send-mailmessage cmdlet uses the from parameter to specify the sender of the message. the a parameter specifies the recipient of the message. the subject parameter uses the text string test email as the message because the optional body parameter is not included.

example 2: send an attachment

This example sends an email message with an attachment.

The send-mailmessage cmdlet uses the from parameter to specify the sender of the message. the a parameter specifies the recipients of the message. the subject parameter describes the content of the message. the body parameter is the content of the message.

The attachments parameter specifies the file in the current directory that is attached to the email message. the priority parameter sets the message to high priority. the -deliverynotificationoption parameter specifies two values, onsuccess and onfailure. the sender will receive email notifications to confirm successful or unsuccessful delivery of the message. the smtpserver parameter sets the smtp server to smtp.fabrikam.com.

See Also:  The Cheapest Way to Ship Luggage, Baggage, & Suitcases | TSI

example 3: send email to a mailing list

This example sends an email message to a mailing list.

The send-mailmessage cmdlet uses the from parameter to specify the sender of the message. the a parameter specifies the recipients of the message. the cc parameter sends a copy of the message to the specified recipient. the bcc parameter sends a blind copy of the message. a blind copy is an email address that is hidden from other recipients. the subject parameter is the message because the optional body parameter is not included.

The credential parameter specifies that the credentials of a domain administrator are used to send the message. The usessl parameter specifies that the secure socket layer (ssl) creates a secure connection.

parameters

-attachments

-bcc

-body

-bodyashtml

-cc

-credential

-delivery notification option

-encoding

-since

-port

-priority

-reply

-smtp server

-subject

-a

-usossl

inputs

string

you can pipe the path and filenames of attachments to send-mailmessage.

exits

none

This cmdlet does not produce any output.

related links

  • about_preference_variables
  • get-badge

Leave a Reply

Your email address will not be published. Required fields are marked *