Skip to content

Instantly share code, notes, and snippets.

@agehlot
Created September 24, 2022 08:21
Show Gist options
  • Save agehlot/dcdb4ff96263a6af34ac62f61025d029 to your computer and use it in GitHub Desktop.
Save agehlot/dcdb4ff96263a6af34ac62f61025d029 to your computer and use it in GitHub Desktop.
This PowerShell script can be used to send an email or to test SMTP settings of any email service provider i.e. Azure SendGrid.
$From = "[email protected]"
$To = "[email protected]"
$SMTPServer = "smtp.sendgrid.net"
$SMTPPort = "587"
$Username = "apikey"
$Password = "[email protected]"
$subject = "Test Email"
$body = "Test email using SendGrid Email Delivery"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$smtp.EnableSSL = $false
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
$smtp.Send($From, $To, $subject, $body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment