Skip to content

Instantly share code, notes, and snippets.

@pkskelly
Created December 2, 2015 20:30
Show Gist options
  • Save pkskelly/0b16f9892234e88c50c3 to your computer and use it in GitHub Desktop.
Save pkskelly/0b16f9892234e88c50c3 to your computer and use it in GitHub Desktop.
Sending Email from PowerShell using SendGrid (in Azure)
$Username ="azure_*********@azure.com"
$Password = ConvertTo-SecureString "********" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$Subject = "SendGrid test"
$Body = "SendGrid testing successful"
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body
@parlevjo2
Copy link

Thanks. Nice Script. Works perfect. Only one thing 1 had changed.
$Username ="azure_*********@azure.com"
should be
$Username ="apikey"
Username is always apikey
The password defines the configuration in Sendgrid

@msniral
Copy link

msniral commented Jul 31, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment