HTTP/2 301
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Fri, 26 Dec 2025 20:50:44 GMT
location: https://www.twilio.com/docs/sendgrid
server: Vercel
strict-transport-security: max-age=63072000
x-vercel-id: bom1::m474w-1766782244126-626c1444d7cb
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, 26 Dec 2025 20:50:44 GMT
last-modified: Fri, 26 Dec 2025 03:08:08 GMT
server: Vercel
strict-transport-security: max-age=63072000
x-matched-path: /docs/sendgrid
x-vercel-cache: HIT
x-vercel-id: bom1::rqck7-1766782244244-58a80a160d6b
etag: W/"58cf87fade88d8d9550ac038735bfb9e"
x-cache: Miss from cloudfront
via: 1.1 fa21a344ea09715302f37efd65799756.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P2
x-amz-cf-id: GArzkypkrPjazOx2JOeGOYY24qeoGVQv6wZL5TihrRS3GyzAiixkdQ==
age: 63755
Twilio SendGrid | SendGrid Docs | Twilio Twilio SendGrid Build transactional and marketing email solutions with Twilio SendGrid.
Take the next steps with Twilio 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 Twilio SendGrid
Send your first email Get started with the Twilio SendGrid Mail Send API and the open-source SDKs.
To send your first message, use the following sample code in your preferred programming language.
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 To implement the previous code sample in your preferred programming language, jump to a quickstart for a full guide.
Do more with email Twilio SendGrid offers tools that build your email communications program.
Gather data from and report on the effectiveness of your email campaigns. Add content and accept files through inbound email.
Use Twilio SendGrid to send and receive email or integrate with a cloud partner for email processing.
Beyond sending your first email Templates and dynamic data Get started with Marketing Campaigns Create well-designed, personalized messages for your Marketing Campaigns.
Build and send with Marketing Campaigns Build your customer engagement infrastructure that fits the unique requirements of your business with the other communication channels from Twilio.
Messaging Send and receive Short Message Service (SMS), Multimedia Messaging Service (MMS), Rich Communication Services (RCS), or WhatsApp messages with Twilio Programmable Messaging.
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.