HTTP/2 301
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Fri, 03 Oct 2025 06:19:36 GMT
location: https://www.twilio.com/docs/sendgrid
server: Vercel
strict-transport-security: max-age=63072000
x-vercel-id: bom1::jd7g5-1759472375999-98e25decc011
HTTP/2 200
content-type: text/html; charset=utf-8
access-control-allow-origin: *
cache-control: public, max-age=0, must-revalidate
content-disposition: inline; filename="sendgrid"
content-encoding: gzip
date: Fri, 03 Oct 2025 06:19:36 GMT
last-modified: Thu, 02 Oct 2025 18:48:02 GMT
server: Vercel
strict-transport-security: max-age=63072000
x-matched-path: /docs/sendgrid
x-vercel-cache: HIT
x-vercel-id: bom1::h9tdd-1759472376106-d40796f1a4b1
etag: W/"a9929c0f9f581a522b5cb4c6d41435ca"
x-cache: Miss from cloudfront
via: 1.1 738500515d323aa084c5d8130ec36544.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P2
x-amz-cf-id: Ty6F9us3_WNUhsauQ1VbYisV9HozpDqTAPu-AlL3WXdSU-l6y1frvg==
age: 32697
SendGrid | SendGrid Docs | Twilio SendGrid Find the documentation, sample code, and developer tools you need to build your transactional and marketing email solutions on the platform that offers a 99% deliverability rate.
Take the next steps with SendGrid
Your app const sgMail = require ( '@sendgrid/mail' );
sgMail. setApiKey (process.env. SENDGRID_API_KEY );
const msg = {
to: 'recipient@example.com' ,
from: 'sender@example.com' ,
subject: 'Ahoy!' ,
html: 'Ahoy, World!' ,
};
sgMail
. send (msg)
. then (( error ) => console. error (error));
Take the next steps with SendGrid
Send your first email Get started quickly with the Twilio SendGrid Mail Send API and our open-source SDKs. The sample code below will send your first message in no time.
C# Go Java Node.js PHP Python Ruby
2 using System . Threading . Tasks ;
4 using SendGrid . Helpers . Mail ;
10 var apiKey = Environment. GetEnvironmentVariable ( "SENDGRID_API_KEY" );
11 var client = new SendGridClient (apiKey);
12 var from = new EmailAddress ( "test@example.com" , "Example User" );
13 var subject = "Sending with Twilio SendGrid is Fun" ;
14 var to = new EmailAddress ( "test@example.com" , "Example User" );
15 var plainTextContent = "and easy to do anywhere, even with C#" ;
16 var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>" ;
17 var msg = MailHelper. CreateSingleEmail (from, to, subject, plainTextContent, htmlContent);
18 var response = await client. SendEmailAsync (msg). ConfigureAwait ( false );
8 " github.com/sendgrid/sendgrid-go "
9 " github.com/sendgrid/sendgrid-go/helpers/mail "
13 from := mail. NewEmail ( "Example User" , "test@example.com" )
14 subject := "Sending with Twilio SendGrid is Fun"
15 to := mail. NewEmail ( "Example User" , "test@example.com" )
16 plainTextContent := "and easy to do anywhere, even with Go"
17 htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"
18 message := mail. NewSingleEmail (from, subject, to, plainTextContent, htmlContent)
19 client := sendgrid. NewSendClient (os. Getenv ( "SENDGRID_API_KEY" ))
20 response, err := client. Send (message)
24 fmt. Println (response.StatusCode)
25 fmt. Println (response.Body)
26 fmt. Println (response.Headers)
2 import java.io.IOException;
5 public static void main ( String [] args ) throws IOException {
6 Email from = new Email ( "test@example.com" );
7 String subject = "Sending with Twilio SendGrid is Fun" ;
8 Email to = new Email ( "test@example.com" );
9 Content content = new Content ( "text/plain" , "and easy to do anywhere, even with Java" );
10 Mail mail = new Mail (from, subject, to, content);
12 SendGrid sg = new SendGrid (System. getenv ( "SENDGRID_API_KEY" ));
13 Request request = new Request ();
15 request. setMethod (Method.POST);
16 request. setEndpoint ( "mail/send" );
17 request. setBody (mail. build ());
18 Response response = sg. api (request);
19 System.out. println (response. getStatusCode ());
20 System.out. println (response. getBody ());
21 System.out. println (response. getHeaders ());
22 } catch (IOException ex ) {
1 const sgMail = require ( '@sendgrid/mail' );
2 sgMail. setApiKey (process.env. SENDGRID_API_KEY );
6 from: 'test@example.com' , // Use the email address or domain you verified above
7 subject: 'Sending with Twilio SendGrid is Fun' ,
8 text: 'and easy to do anywhere, even with Node.js' ,
9 html: '<strong>and easy to do anywhere, even with Node.js</strong>' ,
19 console. error (error.response.body)
1 $email = new \SendGrid\Mail\Mail ();
2 $email -> setFrom ( "test@example.com" , "Example User" );
3 $email -> setSubject ( "Sending with Twilio SendGrid is Fun" );
4 $email -> addTo ( "test@example.com" , "Example User" );
5 $email -> addContent ( "text/plain" , "and easy to do anywhere, even with PHP" );
7 "text/html" , "<strong>and easy to do anywhere, even with PHP</strong>"
9 $sendgrid = new \SendGrid ( getenv ( 'SENDGRID_API_KEY' ));
11 $response = $sendgrid -> send ($email);
12 print $response -> statusCode () . " \n " ;
13 print_r ($response -> headers ());
14 print $response -> body () . " \n " ;
16 echo 'Caught exception: ' . $e -> getMessage () . " \n " ;
3 from sendgrid.helpers.mail import *
5 sg = sendgrid.SendGridAPIClient( api_key = os.environ.get( 'SENDGRID_API_KEY' ))
6 from_email = Email( "test@example.com" )
7 to_email = To( "test@example.com" )
8 subject = "Sending with SendGrid is Fun"
9 content = Content( "text/plain" , "and easy to do anywhere, even with Python" )
10 mail = Mail(from_email, to_email, subject, content)
11 response = sg.client.mail.send.post( request_body = mail.get())
12 print (response.status_code)
4 from = SendGrid :: Email . new ( email: 'test@example.com' )
5 to = SendGrid :: Email . new ( email: 'test@example.com' )
6 subject = 'Sending with Twilio SendGrid is Fun'
7 content = SendGrid :: Content . new ( type: 'text/plain' , value: 'and easy to do anywhere, even with Ruby' )
8 mail = SendGrid :: Mail . new (from, subject, to, content)
10 sg = SendGrid :: API . new ( api_key: ENV [ 'SENDGRID_API_KEY' ])
11 response = sg.client.mail._( 'send' ).post( request_body: mail.to_json)
12 puts response.status_code
14 puts response.parsed_body
Email API quickstarts Jump to an email quickstart in your programming language of choice for a full guide on how to implement the code samples above.
Do more with email Sending email is just the start. With SendGrid, you get rich data that allows you to establish and maintain a complete email program. You can also parse inbound messages to create rich email-based experiences for your customers.
Looking to leverage SendGrid's reliability and scale for your SMTP needs or integrate with a cloud partner such as Azure? You can do that too.
Beyond sending your first email Send with a SendGrid Partner Templates and dynamic data Get started with Marketing Campaigns Create beautifully designed messages, personalized to each recipient, with best in class deliverability when you send with Marketing Campaigns.
Build and send with Marketing Campaigns Explore Twilio's other communication channels to build customer engagement infrastructure that fits the unique requirements of your business.
Messaging Send and receive SMS/MMS and/or WhatsApp messages with the Twilio's Programmable Messaging API.
Product documentation Flex Build your digital engagement center for sales and customer support teams with Twilio Flex.
Product documentation
Need some help? Copyright © 2025 Twilio Inc.