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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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) |