© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SukhijaPowerShell Fast Track https://doi.org/10.1007/978-1-4842-7759-1_6

6. Sending Email

Vikas Sukhija1  
(1)
Waterloo, ON, Canada
 

Sending email is an important aspect of scripting. Say you want to send alerts if a script results in an error, or you want to send bulk emails without utilizing any bulk email tool.

PowerShell has a simple and effective out-of-the-box cmdlet for this purpose right from PowerShell v2. The following is an example of Send-MailMessage, which is prevalent in PowerShell:
Send-MailMessage -SmtpServer "smtpserver" -From "DoNotReply@labtest.com" -To "sukhija@techwizard.cloud " -Subject "Error exception occured " -Body "body of the message" ...

Get PowerShell Fast Track: Hacks for Non-Coders now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.