M
MeshWorld.
SendGrid SMTP Email HowTo Developer Tools 7 min read

How to Use SendGrid SMTP Server for Sending Email

Rachel
By Rachel
| Updated: Mar 24, 2026

SendGrid SMTP is Twilio SendGrid’s outgoing mail relay that lets any app or script send email through SendGrid’s infrastructure. The server is smtp.sendgrid.net on port 587 (STARTTLS) or 465 (SSL). Unlike Gmail or Outlook SMTP where you use your email account credentials, SendGrid authentication uses a fixed username — the literal string apikey — paired with a SendGrid API key you generate in the dashboard. The free plan includes 100 emails/day permanently. This guide covers the exact settings, how to create an API key with the right permissions, and working code examples for PHP, Python, and Node.js.

:::note[TL;DR]

  • SMTP Server: smtp.sendgrid.net
  • Port 587 (STARTTLS) or 465 (SSL)
  • Username: always the literal string apikey — not your email
  • Password: your SendGrid API key
  • Free tier: 100 emails/day with no expiration
  • Sender verification required before sending :::

What are the SendGrid SMTP server settings?

SettingValue
SMTP Serversmtp.sendgrid.net
Port (STARTTLS)587
Port (SSL/TLS)465
EncryptionSTARTTLS (recommended)
AuthenticationRequired
Usernameapikey (literally — not your email)
PasswordYour SendGrid API key

The username being the literal string apikey trips up almost every first-time user. It’s not a placeholder. You type apikey exactly, in lowercase, as the SMTP username. Your actual credential is the API key, which goes in the password field.

How do I create a SendGrid API key for SMTP?

  1. Log in to your SendGrid account at app.sendgrid.com
  2. Go to Settings > API Keys
  3. Click Create API Key
  4. Choose Restricted Access (preferred over Full Access for SMTP)
  5. Under “Mail Send”, enable Mail Send permission
  6. Click Create & View
  7. Copy the API key — it’s shown only once

Store this key somewhere secure. If you lose it, you’ll need to generate a new one — SendGrid doesn’t let you view it again after the creation screen.

:::warning Never commit your SendGrid API key to a public repository. Use environment variables (.env file + dotenv) or your deployment platform’s secrets manager. A leaked SendGrid API key can be used to send spam from your account and will get your account suspended. :::

Do I need to verify my sender address?

Yes. SendGrid requires Sender Verification before you can send email. You have two options:

Single Sender Verification (easier, good for testing):

  • Go to Settings > Sender Authentication
  • Click Verify a Single Sender
  • Fill in the “From” details and submit
  • Click the verification link in the email SendGrid sends you

Domain Authentication (recommended for production):

  • Go to Settings > Sender Authentication > Authenticate Your Domain
  • Add the DNS records SendGrid gives you to your domain’s DNS settings
  • Wait for propagation and verify

Domain authentication improves deliverability and removes SendGrid’s branding from email headers. For any production app, do domain authentication instead of single sender.

The Scenario: You built a password reset system and deployed it. Users click “Forgot Password” and get nothing. You check SendGrid activity logs and see “Sender not verified.” You verified your address during signup but forgot to re-verify after changing the From address in your code. Two-minute fix once you know what to look for.

How do I send email via SendGrid SMTP in code?

PHP with PHPMailer

composer require phpmailer/phpmailer
<?php
use PHPMailer\PHPMailer\PHPMailer;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host       = 'smtp.sendgrid.net';
$mail->SMTPAuth   = true;
$mail->Username   = 'apikey';                        // Always the literal string "apikey"
$mail->Password   = 'SG.xxxxxxxxxxxxxxxxxxxxxx';    // Your SendGrid API key
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port       = 587;

$mail->setFrom('you@yourdomain.com', 'Your Name');  // Must be a verified sender
$mail->addAddress('recipient@example.com');
$mail->Subject = 'Test via SendGrid SMTP';
$mail->Body    = 'Sent through SendGrid SMTP with PHPMailer.';

$mail->send();
echo 'Message sent.';

The From address must be either a single verified sender or on a domain-authenticated domain.

Python with smtplib

import smtplib
from email.mime.text import MIMEText

smtp_server = "smtp.sendgrid.net"
port = 587
username = "apikey"                         # Literal string — not your email
api_key = "SG.xxxxxxxxxxxxxxxxxxxxxx"      # Your SendGrid API key

msg = MIMEText("Sent through SendGrid SMTP.")
msg["Subject"] = "Test via SendGrid SMTP"
msg["From"] = "you@yourdomain.com"         # Must be a verified sender
msg["To"] = "recipient@example.com"

with smtplib.SMTP(smtp_server, port) as server:
    server.ehlo()
    server.starttls()
    server.login(username, api_key)        # Username is "apikey", password is the key
    server.sendmail("you@yourdomain.com", "recipient@example.com", msg.as_string())

print("Email sent.")

Node.js with Nodemailer

npm install nodemailer
const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
  host: "smtp.sendgrid.net",
  port: 587,
  secure: false,  // STARTTLS
  auth: {
    user: "apikey",                          // Literal string "apikey"
    pass: "SG.xxxxxxxxxxxxxxxxxxxxxx",      // Your SendGrid API key
  },
});

async function sendMail() {
  await transporter.sendMail({
    from: '"Your Name" <you@yourdomain.com>', // Verified sender
    to: "recipient@example.com",
    subject: "Test via SendGrid SMTP",
    text: "Sent through SendGrid SMTP with Nodemailer.",
  });
  console.log("Email sent.");
}

sendMail().catch(console.error);

What are the SendGrid SMTP sending limits?

PlanDaily Limit
Free100 emails/day (no expiration)
Essentials (paid)From 40,000/month
Pro (paid)From 100,000/month

The free tier is genuinely free — no trial period, no credit card required, no expiration. 100/day is enough for contact forms, internal tools, and low-volume transactional email. If your app grows beyond that, Essentials plans start at a few dollars/month.

For comparison, Gmail SMTP gives 500/day free but has the account-sharing limitation (you’re tied to a personal Gmail). SendGrid’s free tier is cleaner for app-level email because the credentials are separate from any personal account.

Common SendGrid SMTP errors and how to fix them

535 Authentication credentials invalid Either the API key is wrong/expired, or you used your SendGrid login email as the username instead of the literal string apikey. Check both.

550 5.7.1 The from address does not match a verified Sender Identity Your From address isn’t verified. Complete Single Sender Verification or Domain Authentication for that address.

403 Forbidden (when testing via API) The API key doesn’t have “Mail Send” permission. Regenerate with the correct scope.

Connection refused / timeout Your hosting environment is blocking port 587. Try port 465 with SSL. Some shared hosts block all outbound SMTP — in that case, use SendGrid’s HTTP API instead of SMTP.


FAQ

Is SendGrid SMTP really free forever?

Yes. The 100 emails/day free tier has no time limit. You need a SendGrid account (free) and a verified sender address, but no credit card for the free tier.

Can I use SendGrid SMTP to send from any email address?

No. You can only send from addresses or domains you’ve verified with SendGrid (Single Sender Verification or Domain Authentication). Attempting to send from an unverified address will be rejected.

What’s the difference between SendGrid SMTP and SendGrid API?

Both send email, but the SMTP integration works with any tool that supports standard SMTP configuration. The HTTP API (using SendGrid’s SDK) is more feature-rich — supports dynamic templates, scheduling, suppression lists — and is recommended for production apps. SMTP is simpler to set up for quick integrations.

How do I check if my email was delivered?

In the SendGrid dashboard under Activity, you can see every email sent — delivered, bounced, opened, clicked, or marked as spam. It’s one of SendGrid’s strongest features over basic SMTP providers.

Can I use SendGrid SMTP on shared hosting?

Sometimes. It depends on whether your host allows outbound connections on port 587 or 465. Many shared hosts block outbound SMTP entirely and require you to use their own mail system. If SMTP is blocked, use the SendGrid PHP library with their HTTP API instead.