Save time and feel confident you are set up for long-term success with Email Implementation. Our experts will work as an extension of your team to ensure your email program is correctly set up and delivering value for your business.
You can also send email with the UI and with the API.
Simple Mail Transfer Protocol (SMTP) allows you to send email from one server to another. SendGrid provides an SMTP service that allows you to deliver your email via our servers instead of your own client or server. This means you can count on SendGrid's delivery at scale for your SMTP needs.
SendGrid's SMTP API also allows you to specify custom email handling instructions using a JSON encoded list called the X-SMTPAPI header. The X-SMTPAPI header is parsed by SendGrid to modify your message in the ways you specify.
For a deeper dive into what SMTP is, the benefits of sending an email with SMTP, and how SendGrid can help, see the SMTP Service Crash Course on our blog.
This page will help you send a first test message using Telnet. Once you complete this process, you will be better prepared to explore and build messages using the X-SMTPAPI header.
Be sure to perform the following prerequisites to complete this tutorial.
In the following code samples, greater than and less than symbol are wrapped around placeholder values (e.g., <YOUR_API_KEY>
). You should replace the greater than and less than symbols and the text inside them with an actual value. For example, echo -n '<YOUR_API_KEY>' | openssl base64
will become echo -n 'SG.someactualkey' | openssl base64
if your API key is SG.someactualkey
.
In some cases you will see two sets of greater than and less than symbols wrapping a placeholder. In this case, one set of greater than and less than symbols is required in the actual value and should not be replaced. For example, From: "Example" <<example@example.com>>
will become From: "Example" <example@example.com>
.
Once you have your terminal open and have saved your API key, you must Base64 encode the API key. Note that it is not secure to put your API key into an external webpage for a conversion, so we recommend using a conversion in your terminal. If you are on Mac or Linux, you can use the pre-installed OpenSSL package to Base64 encode a string with the following command.
echo -n '<YOUR_API_KEY>' | openssl base64
Save your encoded key for a later. Also, be sure you have not included any newline or whitespace characters by accident. This can happen when copying the encoded key from a shell that line wraps output. SMTP is a line-oriented protocol, and linefeed characters will prevent you from authenticating successfully.
Telnet does not register backspaces correctly, so you must type your commands correctly or copy and paste them from this page.
You may need to install Telnet on your machine. Telnet comes natively on some operating systems; However, recent releases of MacOS no longer include Telnet, and Telnet must be enabled manually on Windows 10 and Windows 11.
You can install Telnet on MacOS using Homebrew.
To enable Telnet on Windows, navigate to Windows Features > Turn Windows Features on or off from the Windows Control Panel. Check the box next to Telnet Client, and select OK.
TELNET smtp.sendgrid.net 25
SendGrid accepts unencrypted and TLS connections on ports 25, 587, & 2525. You can also connect via SSL on port 465. Many hosting providers and ISPs block port 25 as a default practice. If your Telent session continually times out or will not connect using port 25, it is likely that your ISP or hosting provider is blocking the port. You can contact your host/ISP to find out which ports are open for outgoing SMTP relay. We recommend using port 587 to avoid any rate limiting that your server host may apply.
AUTH LOGIN
The mail server will respond with 334 VXNlcm5hbWU6
, which is a Base64 encoded request for your username.
YXBpa2V5
and press
Enter
on your keyboard. Twilio SendGrid requires you to authenticate using an API key. When using Basic Authentication and an API key, you must use the string
apikey
in place of your account username. The string
apikey
is
YXBpa2V5
when Base64 encoded, which is why we use it in this step.
The mail server will respond with 334 UGFzc3dvcmQ6
. This response is a Base64 encoded request for your password (your API Key).
The mail server will respond with 235 Authentication successful
. Getting this far indicates that your connection to smtp.sendgrid.net
over the chosen port is open and that your API key is valid.
MAIL FROM: <SENDER_EMAIL>
The mail server will respond with 250 Sender address accepted
.
RCPT TO: <RECIPIENT_ADDRESS>
Note that you can add more RCPT TO addresses during this step. Repeat the process by adding another RCPT TO command and pressing Enter for each recipient you intend to deliver the message to.
The mail server will respond with 250 Recipient address accepted
after each recipient is added.
DATA
and press
Enter
.
The mail server will respond with 354 Continue
. Unlike the MAIL FROM and RCPT TO commands, which are part of the email envelope, the DATA command is not meant to contain information that routes your email from a sender to a recipient. Instead, DATA allows you to modify the content of your message.
To: "<RecipientName>" <<RecipientEmailAddress>>
From: "<SenderName>" <<SenderEmail>>
Subject: <EMAIL_SUBJECT>
"<MESSAGE>"
For example:
“This is a test for the SMTP relay."
.
, and then pressing
Enter
.
The mail server will return 250 Ok: queued as <examplestring1234>
. This means the email has been queued to send. The queue moves very quickly, and you should see mail delivered to the designated recipients shortly.
quit
and pressing
Enter
.
The full command should look like the following example.
1235 Authentication successful2MAIL FROM:tiramisu@example.com3250 Sender address accepted4RCPT TO:person1@sendgrid.com5250 Recipient address accepted6DATA7354 Continue8From: "Tira Misu" <tiramisu@example.com>9To: "Person 1" <person1@sendgrid.com>10Subject: Test message subject1112"This is the test message body."13.14250 Ok: queued as Yo60h6C5ScGPeP5fUWU3K
Now that you've sent a test email, learn to integrate your servers with our SMTP service.
Message size limit: The total message size should not exceed 20MB. This includes the message itself, headers, and the combined size of any attachments.
Save time and feel confident you are set up for long-term success with Email Implementation. Our experts will work as an extension of your team to ensure your email program is correctly set up and delivering value for your business.