SOLFIND
Web Lens
Portal home

Twilio SendGrid | SendGrid Docs | Twilio

https://www.twilio.com/docs/sendgrid • 302 KB fetched
Open original page


Twilio SendGrid | SendGrid Docs | Twilio Skip to content Skip to navigation Skip to topbar
Twilio SendGrid Docs

Twilio SendGrid Email concepts SendGrid Onboarding Guides For Developers SendGrid API Reference User Interface Documentation Data Residency Glossary

Twilio SendGrid Docs

Search

Search
Search
* Log in

* Sign up

Twilio SendGrid
Build transactional and marketing email solutions with Twilio SendGrid.
Let's build

Take the next steps with Twilio SendGrid

Send your first email
Do more with email
Get started with Marketing Campaigns

1

Twilio servers

2

Your app const sgMail = require ( '@sendgrid/mail' );

sgMail. setApiKey (process.env. SENDGRID_API_KEY );

const msg = {

to: '[email protected]' ,

from: '[email protected]' ,

subject: 'Ahoy!' ,

html: 'Ahoy, World!' ,

};

sgMail

. send (msg)

. then (( error ) => console. error (error));

View complete examples

3

Ahoy, world!

Take the next steps with Twilio SendGrid

Send your first email
Do more with email
Get started with Marketing Campaigns

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

Copy code block

1 using System ;

2 using System . Threading . Tasks ;

3 using SendGrid ;

4 using SendGrid . Helpers . Mail ;

5

6 class Program

7 {

8 static async Task Main ()

9 {

10 var apiKey = Environment. GetEnvironmentVariable ( "SENDGRID_API_KEY" );

11 var client = new SendGridClient (apiKey);

12 var from = new EmailAddress ( "[email protected]" , "Example User" );

13 var subject = "Sending with Twilio SendGrid is Fun" ;

14 var to = new EmailAddress ( "[email protected]" , "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 );

19 }

20 }

Copy code block

1 package main

2

3 import (

4 " fmt "

5 " log "

6 " os "

7

8 " github.com/sendgrid/sendgrid-go "

9 " github.com/sendgrid/sendgrid-go/helpers/mail "

10 )

11

12 func main () {

13 from := mail. NewEmail ( "Example User" , "[email protected]" )

14 subject := "Sending with Twilio SendGrid is Fun"

15 to := mail. NewEmail ( "Example User" , "[email protected]" )

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)

21 if err != nil {

22 log. Println (err)

23 } else {

24 fmt. Println (response.StatusCode)

25 fmt. Println (response.Body)

26 fmt. Println (response.Headers)

27 }

28 }

Copy code block

1 import com.sendgrid. * ;

2 import java.io.IOException;

3

4 public class Example {

5 public static void main ( String [] args ) throws IOException {

6 Email from = new Email ( "[email protected]" );

7 String subject = "Sending with Twilio SendGrid is Fun" ;

8 Email to = new Email ( "[email protected]" );

9 Content content = new Content ( "text/plain" , "and easy to do anywhere, even with Java" );

10 Mail mail = new Mail (from, subject, to, content);

11

12 SendGrid sg = new SendGrid (System. getenv ( "SENDGRID_API_KEY" ));

13 Request request = new Request ();

14 try {

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 ) {

23 throw ex;

24 }

25 }

26 }

Copy code block

1 const sgMail = require ( '@sendgrid/mail' );

2 sgMail. setApiKey (process.env. SENDGRID_API_KEY );

3

4 const msg = {

5 to: '[email protected]' ,

6 from: '[email protected]' , // 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>' ,

10 };

11

12 ( async () => {

13 try {

14 await sgMail. send (msg);

15 } catch (error) {

16 console. error (error);

17

18 if (error.response) {

19 console. error (error.response.body)

20 }

21 }

22 })();

Copy code block

1 $email = new \SendGrid\Mail\Mail ();

2 $email -> setFrom ( "[email protected]" , "Example User" );

3 $email -> setSubject ( "Sending with Twilio SendGrid is Fun" );

4 $email -> addTo ( "[email protected]" , "Example User" );

5 $email -> addContent ( "text/plain" , "and easy to do anywhere, even with PHP" );

6 $email -> addContent (

7 "text/html" , "<strong>and easy to do anywhere, even with PHP</strong>"

8 );

9 $sendgrid = new \SendGrid ( getenv ( 'SENDGRID_API_KEY' ));

10 try {

11 $response = $sendgrid -> send ($email);

12 print $response -> statusCode () . " \n " ;

13 print_r ($response -> headers ());

14 print $response -> body () . " \n " ;

15 } catch ( Exception $e) {

16 echo 'Caught exception: ' . $e -> getMessage () . " \n " ;

17 }

Copy code block

1 import sendgrid

2 import os

3 from sendgrid.helpers.mail import *

4

5 sg = sendgrid.SendGridAPIClient( api_key = os.environ.get( 'SENDGRID_API_KEY' ))

6 from_email = Email( "[email protected]" )

7 to_email = To( "[email protected]" )

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)

13 print (response.body)

14 print (response.headers)

Copy code block

1 require 'sendgrid-ruby'

2 include SendGrid

3

4 from = SendGrid :: Email . new ( email: '[email protected]' )

5 to = SendGrid :: Email . new ( email: '[email protected]' )

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)

9

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

13 puts response.body

14 puts response.parsed_body

15 puts response.headers

Email API quickstarts To implement the previous code sample in your preferred programming language, jump to a quickstart for a full guide.
C#
Go
Java
Node.js
PHP
Python
Ruby

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

* Get started with the Email API

* Set up domain authentication

* Review the SendGrid v3 API reference

* Review the Email glossary

Send email

* Send email using SMTP

* Build an X-SMTPAPI Header

* Send email using Microsoft Azure

Templates and dynamic data

* Send an email with Dynamic Templates

* Send personalized email messages

* Personalize messages with Handlebars

Analytics and reporting

* Get started with the Event webhook

* Review the Event webhook reference

* Use the Email Activity Feed

* Review the SendGrid Engagement Quality API

Account and settings API Keys
Subusers
Teammates
Domain Authentication
Single Sign-On (SSO)

Parsing email

* Configure the Inbound Parse webhook

* Review Inbound Parse API

SDKs and tools C# Go Java Node.js PHP Python Ruby OpenAPI

Get started with Marketing Campaigns
Create well-designed, personalized messages for your Marketing Campaigns.

Build and send with Marketing Campaigns

* Send email using Marketing Campaigns

* Get started with automation

Manage contacts

* Create and manage contacts

* Build your contact list

* Segment your contacts

* Use custom fields

Design your messages

* Build templates with email designs

* Design messages with the Design and Code Editor

* Add dynamic content with Handlebars in Marketing Campaigns

Related products
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

Voice Send and receive voice calls through your app with Twilio Programmable Voice.
Product documentation

Flex Build your digital engagement center for sales and customer support teams with Twilio Flex.
Product documentation

Need some help?

We all do sometimes; code is hard. Get help now from our support team , or lean on the wisdom of the crowd by browsing the SendGrid tag on Stack Overflow.

Terms of service
Privacy Policy
Copyright © 2026 Twilio Inc.

Links found on this page

  1. Skip to content [direct]
  2. Email concepts [direct]
  3. SendGrid Onboarding Guides [direct]
  4. For Developers [direct]
  5. SendGrid API Reference [direct]
  6. User Interface Documentation [direct]
  7. Data Residency [direct]
  8. Glossary [direct]
  9. Twilio SendGrid Docs [direct]
  10. Log in [direct]
  11. Sign up [direct]
  12. View complete examples [direct]
  13. C# [direct]
  14. Go [direct]
  15. Java [direct]
  16. Node.js [direct]
  17. PHP [direct]
  18. Python [direct]
  19. Ruby [direct]
  20. Get started with the Email API [direct]
  21. Set up domain authentication [direct]
  22. Review the Email glossary [direct]
  23. Send email using SMTP [direct]
  24. Build an X-SMTPAPI Header [direct]
  25. Send email using Microsoft Azure [direct]
  26. Send an email with Dynamic Templates [direct]
  27. Send personalized email messages [direct]
  28. Personalize messages with Handlebars [direct]
  29. Get started with the Event webhook [direct]
  30. Review the Event webhook reference [direct]
  31. Use the Email Activity Feed [direct]
  32. Review the SendGrid Engagement Quality API [direct]
  33. API Keys [direct]
  34. Subusers [direct]
  35. Teammates [direct]
  36. Single Sign-On (SSO) [direct]
  37. Configure the Inbound Parse webhook [direct]
  38. Review Inbound Parse API [direct]
  39. C# [direct]
  40. Go [direct]
  41. Java [direct]
  42. Node.js [direct]
  43. PHP [direct]
  44. Python [direct]
  45. Ruby [direct]
  46. OpenAPI [direct]
  47. Send email using Marketing Campaigns [direct]
  48. Get started with automation [direct]
  49. Create and manage contacts [direct]
  50. Build your contact list [direct]
  51. Segment your contacts [direct]
  52. Use custom fields [direct]
  53. Build templates with email designs [direct]
  54. Design messages with the Design and Code Editor [direct]
  55. Add dynamic content with Handlebars in Marketing Campaigns [direct]
  56. Product documentation [direct]
  57. Product documentation [direct]
  58. Product documentation [direct]
  59. support team [direct]
  60. SendGrid tag [direct]
  61. Terms of service [direct]
  62. Privacy Policy [direct]