SendGrid

Say goodbye to email fire drills by building and monitoring your email solution on a trusted foundation. Our Email API and purpose-built MTA send over 100B emails per month for businesses of all sizes. On our collaborative platform, your teams can work together to create email templates that send programmatically, analyze email performance, and troubleshoot diagnostically to identify delivery issues.

Getting your emails delivered is our #1 priority - we understand that lost emails are lost customers. Our email platform provides streamlined tools and recommendations to achieve optimal inbox placement. With infrastructure that automates queue handling and throttles threat detection, Twilio SendGrid enables your teams to focus on building innovative customer experiences by optimizing for deliverability, scalability, and security.

Use Cases

  • Deliver timely alerts and notifications - from password resets to purchase confirmations.
  • Create personalized promotions based on triggers and segmentation.
  • Optimize email marketing campaigns with automation and intelligence.
  • Connect with consumers at the perfect time to influence a purchase, improving customer loyalty and lead conversions.

Account Setup

Two Factor AuthenticationTwo-factor authentication (2FA) is required by Twilio SendGrid in order to protect senders from account takeovers. To enable 2FA, navigate to Settings > Two-Factor Authentication in the Twilio SendGrid App, and click Add Two-Factor Authentication. To learn more about setting up 2FA, please read the documentation.

API KeysAPI Keys are used by your application, mail client, or website to authenticate access to Twilio SendGrid services. Unlike a username and password, an API key can be scoped to provide access to the minimum services needed by your application, and you can revoke an API key at any time without needing to change your username and password. For these reasons, API keys are required when connecting to all of Twilio SendGrid’s services. To learn more about creating API keys, please visit the Twilio SendGrid Knowledge Center.

Getting Started After Deploying SendGrid

Integrate and deliver email in minutes with our RESTful APIs and SMTP, libraries to support your programming language, and detailed documentation. Twilio SendGrid’s Email API provides support in seven different programming languages, including C#, Go, Java, Node.js, PHP, Python, and Ruby.

Code Examples

curl

curl --request POST
  --url https://api.sendgrid.com/v3/mail/send
  --header 'Authorization: Bearer YOUR_API_KEY'
  --header 'Content-Type: application/json'
  --data '{"personalizations": [{"to": [{"email": "recipient@example.com"}]}],"from": {"email": "sendeexampexample@example.com"},"subject": "Hello, World!","content": [{"type": "text/plain", "value": "Heya!"}]}'

Node.js

// using SendGrid's Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
const sendgrid = require("sendgrid")("SENDGRID_APIKEY");
const email = new sendgrid.Email();

email.addTo("test@sendgrid.com");
email.setFrom("you@youremail.com");
email.setSubject("Sending an email with SendGrid is Fun");
email.setHtml("and easy to do anywhere, even with Node.js");

sendgrid.send(email);

Python

# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
from_email = Email('test@example.com')
to_email = To('test@example.com')
subject = 'Sending with SendGrid is Fun'
content = Content('text/plain', 'and easy to do anywhere, even with Python')
mail = Mail(from_email, to_email, subject, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)

Ruby

# using SendGrid's Ruby Library
# https://github.com/sendgrid/sendgrid-ruby
require 'sendgrid-ruby'
include SendGrid

from = SendGrid::Email.new(email: 'test@example.com')
to = SendGrid::Email.new(email: 'test@example.com')
subject = 'Sending with SendGrid is Fun'
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = SendGrid::Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)
puts response.status_code
puts response.body
puts response.headers