Skip to content

How To: Send an Email Through PowerShell Scripts How to send an email through PowerShell Scripts

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.

  1. Open your PowerShell ISE. Following are some specifications required for emailing:
  • $EmailFrom : Specifies the sender information – The example in Figure 1 shows abc.01@gmail.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 command
    Figure 1 - PowerShell script for sending an email
    Figure 1 - PowerShell script for sending an email
  1. 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
    Figure 2 – Message box indicating credentials are required
  2. Specify the password of your Gmail account and click OK.
  3. You can now check your email. Figure 3 shows what it looks like to receive an email.
    Figure 3 – Email notification in PowerShell
    Figure 3 – Email notification in PowerShell

 

If you have any questions about this or other Dynamics NAV or Business Central topic for any version, contact ArcherPoint.

Read more "How To" blogs from ArcherPoint for practical advice on using Microsoft Dynamics Business Central or NAV.

If you are interested in NAV/Business Central development, check out our collection of NAV Development Blogs.

Blog Tags: 
Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Watch us on YouTube
Get Help Now