Send Email From the Command Line

Australian internet service providers (ISP) allow to send emails using their SMTP relays.

It’s pretty easy to send an e-mail from PowerShell:

send-mailmessage -from "Peter <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -to "Oscar <This email address is being protected from spambots. You need JavaScript enabled to view it.>" -subject "Hello! How r u?" -smtp mail.bigpond.com -body "Buy one, get one free!!!"

You can also use server with authentication:

$EmailFrom = This email address is being protected from spambots. You need JavaScript enabled to view it.
$EmailTo = This email address is being protected from spambots. You need JavaScript enabled to view it.
$Subject = "Hello! How r u?"
$Body = "Buy one, get one free!!!"
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

You will need to change the following:
$EmailFrom = Your GMail address.
$EmailTo = The recipient’s email address.
$Subject = What you want the subject of the mail to say.
$Body = What you want the main part of the mail to say.
usr = You will need to replace this with your GMail username.
pass = You will need to replace this with your GMail password.

Tips: Send HTML Formatted Emails using PowerShell.


AUST IT - Computer help out of hours, when you need it most.

Find out why we do it for less.

About

AUST IT will help you resolve any technical support issues you are facing onsite or remotely via remote desktop 24/7. More...

Contacts

Reservoir, Melbourne,
3073, VIC, Australia

Phone: 0422 348 882

This email address is being protected from spambots. You need JavaScript enabled to view it.

Sydney: 0481 837 077

Connect

Join us in social networks to be in touch.

Newsletter

Complete the form below, and we'll send you our emails with all the latest AUST IT news.