How to send an email with attachment using PowerShell

Configurare noua (How To)

Situatie

This example sends an email message with an attachment.

Solutie

Run the PowerShell command:

Send-MailMessage -From ‘User01 <user01@test.com>’ -To ‘User02 <user02@test.com>’, ‘User03 <user03@test.com>’ -Subject ‘Sending the Attachment’ -Body “Forgot to send the attachment. Sending now.” -Attachments .\data.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer ‘smtp.test.com’

The Send-MailMessage cmdlet uses the From parameter to specify the message’s sender. The To parameter specifies the message’s recipients. 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 the success or failure of the message delivery. The SmtpServer parameter sets the SMTP server to smtp.test.com.

Tip solutie

Permanent

Voteaza

(6 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?