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 = "$email@example.com"|
|$EmailTo = "firstname.lastname@example.org"|
|$Subject = "Job Name: $JOBNAME, $RESULT, Errors: $ERRORS, Synced: $SYNCOK"|
|$Body = "$ALLARGS"|
|$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)|