SendGrid email using PowerShell

Have you ever wanted to automate sending email to anywhere via your SendGrid account?

Maybe you have moved to the Office 365 and now that you don’t have an Exchange server on-prem anymore, you don’t have the luxury to use your own Exchange server as an SMTP server. You can’t use Office 365 Exchange Online as an SMTP server…..

SendGrid to the answer – below is some PowerShell which will assist you in the automation of sending email using SendGrid.


$MyService = @()
$EmailFrom = @()
$Subject = @()
$Body = @()
$computer = @()
$computer = gc env:computername
$SMTPServer = "smtp.sendgrid.net"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("<USERNAME>", "<PASSWORD>");
$EmailFrom = "$computer@domain.com.au"
$EmailTo = "someone@domain.com"
$Subject = "Job Name: $JOBNAME, $RESULT, Errors: $ERRORS, Synced: $SYNCOK"
$Body = "$ALLARGS"
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s