Email Api

curl –request POST \
–url https://api.sendgrid.com/v3/mail/send \
–header “Authorization: Bearer $SENDGRID_API_KEY” \
–header ‘Content-Type: application/json’ \
–data ‘{“personalizations”: [{“to”: [{“email”: “test@example.com”}]}],”from”: {“email”: “test@example.com”},”subject”: “Sending with SendGrid is Fun”,”content”: [{“type”: “text/plain”, “value”: “and easy to do anywhere, even with cURL”}]}’
view raw gistfile1.txt hosted with ❤ by GitHub
// using Twilio SendGrid’s v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
const sgMail = require(@sendgrid/mail);
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: test@example.com,
from: test@example.com,
subject: Sending with Twilio SendGrid is Fun,
text: and easy to do anywhere, even with Node.js,
html: <strong>and easy to do anywhere, even with Node.js</strong>,
};
sgMail.send(msg);
view raw v3-hello-email.js hosted with ❤ by GitHub
# using SendGrid’s Ruby Library
# https://github.com/sendgrid/sendgrid-ruby
require sendgrid-ruby
include SendGrid
from = Email.new(email: test@example.com)
to = Email.new(email: test@example.com)
subject = Sending with SendGrid is Fun
content = Content.new(type: text/plain, value: and easy to do anywhere, even with Ruby)
mail = 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
view raw v3-hello-email.rb hosted with ❤ by GitHub
# using SendGrid’s Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email=from_email@example.com,
to_emails=to@example.com,
subject=Sending with Twilio SendGrid is Fun,
html_content=<strong>and easy to do anywhere, even with Python</strong>)
try:
sg = SendGridAPIClient(os.environ.get(SENDGRID_API_KEY))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
view raw v3-hello-email.py hosted with ❤ by GitHub
// using SendGrid’s Go Library
// https://github.com/sendgrid/sendgrid-go
package main
import (
fmt
log
os
github.com/sendgrid/sendgrid-go
github.com/sendgrid/sendgrid-go/helpers/mail
)
func main() {
from := mail.NewEmail(Example User, test@example.com)
subject := Sending with SendGrid is Fun
to := mail.NewEmail(Example User, test@example.com)
plainTextContent := and easy to do anywhere, even with Go
htmlContent := <strong>and easy to do anywhere, even with Go</strong>
message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
client := sendgrid.NewSendClient(os.Getenv(SENDGRID_API_KEY))
response, err := client.Send(message)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
view raw v3-hello-email.go hosted with ❤ by GitHub
<?php
require vendor/autoload.php; // If you’re using Composer (recommended)
// Comment out the above line if not using Composer
// require(“<PATH TO>/sendgrid-php.php”);
// If not using Composer, uncomment the above line and
// download sendgrid-php.zip from the latest release here,
// replacing <PATH TO> with the path to the sendgrid-php.php file,
// which is included in the download:
// https://github.com/sendgrid/sendgrid-php/releases
$email = new \SendGrid\Mail\Mail();
$email->setFrom(test@example.com, Example User);
$email->setSubject(Sending with SendGrid is Fun);
$email->addTo(test@example.com, Example User);
$email->addContent(text/plain, and easy to do anywhere, even with PHP);
$email->addContent(
text/html, <strong>and easy to do anywhere, even with PHP</strong>
);
$sendgrid = new \SendGrid(getenv(SENDGRID_API_KEY));
try {
$response = $sendgrid->send($email);
print $response->statusCode() . \n;
print_r($response->headers());
print $response->body() . \n;
} catch (Exception $e) {
echo Caught exception: . $e->getMessage() .\n;
}
view raw v3-hello-email.php hosted with ❤ by GitHub
// using SendGrid’s Java Library
// https://github.com/sendgrid/sendgrid-java
import com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
Email from = new Email(test@example.com);
String subject = Sending with SendGrid is Fun;
Email to = new Email(test@example.com);
Content content = new Content(text/plain, and easy to do anywhere, even with Java);
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(System.getenv(SENDGRID_API_KEY));
Request request = new Request();
try {
request.setMethod(Method.POST);
request.setEndpoint(mail/send);
request.setBody(mail.build());
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
}
view raw v3-hello-email.java hosted with ❤ by GitHub
// using SendGrid’s C# Library
// https://github.com/sendgrid/sendgrid-csharp
using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Threading.Tasks;
namespace Example
{
internal class Example
{
private static void Main()
{
Execute().Wait();
}
static async Task Execute()
{
var apiKey = Environment.GetEnvironmentVariable(NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY);
var client = new SendGridClient(apiKey);
var from = new EmailAddress(test@example.com, Example User);
var subject = Sending with SendGrid is Fun;
var to = new EmailAddress(test@example.com, Example User);
var plainTextContent = and easy to do anywhere, even with C#;
var htmlContent = <strong>and easy to do anywhere, even with C#</strong>;
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
}
}
}
view raw v3-hello-email.cs hosted with ❤ by GitHub

Integrate and Deliver via SMTP or API in 5 Minutes or Less

Our SMTP relay setup and flexible Web and SMTP APIs provide a customizable integration approach for your transactional email.

  • Integrate with support from multiple development frameworks and client libraries, including Node.js, Ruby, Python, Go, PHP, Java, and C#.
  • Get answers when you need them through our robust documentation, support, video tutorials, and online community.
  • Access account statistics and engagement data in real-time through our Event Webhook.

Optimize Your Inbox Delivery and Engagement

Email delivery is our passion. Our industry-leading email delivery platform includes tools and expertise to make sure your emails get to the inbox and drive engagement.

  • Improve deliverability with domain and link customization, whether sending from shared IP pools or a dedicated IP.
  • Eliminate domain spoofing and phishing emails with our custom SPF and DKIM record creation.
  • Have your email monitored and managed by our 30+ member team of deliverability experts.
  • Maximize your email engagement to your mobile app experience with our universal linking functionality.

Learn Why We’re the Delivery Experts

Secure Your Sending Environment

You trust your data to us and we take that very seriously. We have a number of measures in place to keep that trust.

  • Secure your email with two-factor authentication, precise teammate permissions, API key permissions, IP Access Management, and more.
  • Safeguard your messages with enforced or opportunistic TLS.
  • Benefit from continuous mail flow through our secure, distributed, and redundant data centers.

Expedite Your Integration With Robust Documentation

Integrate and easily send email from your app, whether it’s a CMS, framework, CRM, or your own code.

  • Try it out, integrate, send, and track your emails with help from our interactive online documentation.
  • Get started quickly with our code examples and helper functions available in a variety of languages, including: Python, PHP, Go Lang, Java, Node.js, Ruby, and C#.

Share a Single Email Platform With Your Whole Team

SendGrid powers email delivery for your entire team, providing one platform for all your email sending needs.

  • Enjoy secure account sharing by specifying access levels for your developers, marketers, accountants, and designers.
  • Consume recipient engagement data with our powerful dashboard that is easily accessible for non-technical users.
  • Streamline your template creation workflows with our marketing and transactional email template tools.

Gain Peace of Mind With Email Sending Visibility

Troubleshooting occasional email delivery issues is unavoidable. To help, we provide added visibility into each of your email messages with our enhanced email activity feed.

  • Easily pinpoint a specific email message with our email activity feed’s advanced search and multiple filter capabilities—including partial subject
    line search.
  • Understand the entire journey of that message with sequential event organization —detailed from processed to delivered, through to opened
    and clicked.
  • Harness the freedom to access the email activity data you need when you need it, with the additional email activity history option* (up to 30 days visible in the UI), exportable CSV, and details-by-email API.
  • *Please note some limitations apply. Email volumes over 100 million are not included. An additional purchase is required for additional email history up to 30 days as well as new events API endpoints.

What Our Customers are Saying

Integration took 3 lines of code and about 30 seconds.


Bart Lorang
CEO and Co-founder

SendGrid was the only provider that had the email tools, expertise, and platform flexibility to let us put transactional email infrastructure on autopilot.


Oliver Hurst-Hiller
CTO and Head of Product

SendGrid has been instrumental in scaling our email without interruptions. I’m used to working on imperfect systems, so it’s nice to have things just work for me.


Alex Karweit
Engineering Lead

Over 80,000 paying customers trust SendGrid to send more than 50 billion emails every month.

The SendGrid Difference

Proven Deliverability

We offer domain authentication, compliance and deliverability coaching, and proactive ISP outreach to ensure you achieve optimal inbox delivery.

Scale With Confidence

Whether you’re a startup or a large enterprise, we can handle your important emails. Our world-class platform delivers more than 50 billion emails per month.

Email Expertise

With SendGrid, you have an expert in your corner. Our Customer Success and Support Teams give you the information and guidance you need, when you need it.

Send With Confidence

Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.

See Plans and Pricing