PowerShell Sending Email

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

A useful technique for Exchange Server administrators is to be able to send email messages via SMTP from PowerShell. Depending on the version of PowerShell installed on your computer or server, there are multiple ways to send emails via powershell. There is a native cmdlet option that is simple and easy to use. It uses the cmdlet Send-MailMessage.

Parameters

ParameterDetails
Attachments<String[]>Path and file names of files to be attached to the message. Paths and filenames can be piped to Send-MailMessage.
Bcc<String[]>Email addresses that receive a copy of an email message but does not appear as a recipient in the message. Enter names (optional) and the email address (required), such as Name [email protected] or [email protected].
Body <String_>Content of the email message.
BodyAsHtmlIt indicates that the content is in HTML format.
Cc<String[]>Email addresses that receive a copy of an email message. Enter names (optional) and the email address (required), such as Name [email protected] or [email protected].
CredentialSpecifies a user account that has permission to send message from specified email address. The default is the current user. Enter name such as User or Domain\User, or enter a PSCredential object.
DeliveryNotificationOptionSpecifies the delivery notification options for the email message. Multiple values can be specified. Delivery notifications are sent in message to address specified in To parameter. Acceptable values: None, OnSuccess, OnFailure, Delay, Never.
EncodingEncoding for the body and subject. Acceptable values: ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, OEM.
FromEmail addresses from which the mail is sent. Enter names (optional) and the email address (require), such as Name [email protected] or [email protected].
PortAlternate port on the SMTP server. The default value is 25. Available from Windows PowerShell 3.0.
PriorityPriority of the email message. Acceptable values: Normal, High, Low.
SmtpServerName of the SMTP server that sends the email message. Default value is the value of the $PSEmailServer variable.
SubjectSubject of the email message.
ToEmail addresses to which the mail is sent. Enter names (optional) and the email address (required), such as Name [email protected] or [email protected]
UseSslUses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail


Got any PowerShell Question?