Use Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send.

Send mail through SendGrid Web API using PowerShell

Learn how to use the Twilio SendGrid Web API v3 to send mail with PowerShell

Home » Send mail through SendGrid Web API using PowerShell

I found the SendGrid API documentation is lacking an simple PowerShell example to use their API, so here it is: Use Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send to send mail using PowerShell.

The SendGrid v3 Web API provides a REST-like interface that enables you to send email at scale, ensuring your application can handle high-volume email with ease. Learn to use PowerShell to send mails through SendGrid.

Learn how to use the Twilio SendGrid Web API v3 to send mail with PowerShell without additional modules.

# fill in your API key
$apikey = ''

$headers = @{
  Authorization="Bearer ${apikey}"
}

$bodyParams = @'
  {
    "personalizations": [
      {
        "to": [
          {
            "email": "recipient@example.net",
            "name": "Firstname Lastname"
          }
        ],
        "subject": "Hello, World!"
      }
    ],
    "content": [
      {
        "type": "text/plain",
        "value": "Heya!"
      }
    ],
    "from": {
      "email": "sender@example.com",
      "name": "Firstname Lastname"
    },
    "reply_to": {
      "email": "sender@example.net",
      "name": "First Name"
    }
  }
'@

Invoke-RestMethod -Method POST `
  -Uri https://api.sendgrid.com/v3/mail/send `
  -Headers $headers `
  -ContentType 'application/json' `
  -Body $bodyParams

This is it.

Configurable Sending in the EU

This feature empowers you to send outbound emails directly from servers located within the European Union, ensuring compliance with GDPR regulations and enhancing data privacy. If you need to use the EU region, verify your API key is valid and change the URI to api.eu.sendgrid.com.

Conclusion

Twilio SendGrid is a company having their security options in place for secure mail sending. With security options you have to think about SPF, DNSSEC, StartTLS, encryption, authentication and account protection features. These include opportunistic TLS, enforced TLS, DKIM, SPF, DMARC, API keys with granular permissions, two-factor authentication, and IP Access Management.

Being able to send an email through SendGrid, using either PowerShell or .NET, can come in handy when sending DevOps reporting mails. This is a nice addition to my Send email wiht PowerShell post, but without additional modules.

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments