May 29, 2019
Sending an Email Through PowerShell Coding
Typically, people use Outlook or other tool for emails. But if you want to be able to send an email without having to go into Outlook because it can cause you to get distracted, taking you away from what you’re working on, there is another method. This blog explains how to use a PowerShell script to send an email.
- Open your PowerShell ISE. Following are some specifications required for emailing:
- $EmailFrom : Specifies the sender information – The example in Figure 1 shows email@example.com sending an email to abc.01gmail.com
- $EmailTo: Specifies the recipient of the mail
- $subject: Specifies the subject of the email you want to send
- $Body: Specifies the body of the message
- $SMTPServer: The mail server you will be using to send the email
- $SMTPClient: The name of the client; create a newobject and call the system.netmail.api and pass the smtpserver info
- $SMTPClient.send: Specifies sending the email using .send commandFigure 1 - PowerShell script for sending an email
- Press F5 to run the script. You will receive a message box like that one shown in Figure 2.
Figure 2 – Message box indicating credentials are required
- Specify the password of your Gmail account and click OK.
- You can now check your email. Figure 3 shows what it looks like to receive an email.
Figure 3 – Email notification in PowerShell
- Login Error: Communication protocol mismatch between client and server
- Creating a Date Table in Power BI
- How to Make Measures Total Correctly in Power BI Tables
- The Microsoft Technology Stack – What It Is and Why You Should Care
- The Top Eight KPIs Retailers Should Be Tracking (with Formulas) for Your Retail KPI Dashboard