Troubleshooting Twilio SendGrid email delivery delays and latency

If customer Experiencing delays, check our Status Page for the current state of all Twilio SendGrid Services.

As you send email, you may encounter scenarios where mail seems to take more time than it should to get to its final destination. Mail delays can manifest in a number of ways, so we've collected a list of tips to help you try to track them down. This guide covers the following topics for diagnosing and resolving your issues:

Please start at the top, and walk through each of the troubleshooting steps as you work your way down the page.

Verify you’re using an official Twilio SendGrid library

If you are integrated with Twilio SendGrid using code, we highly recommend using the official Twilio SendGrid libraries. You can find links for all of our official SDKs and getting started tutorials at API Libraries (SendGrid docs).

Use the Twilio SendGrid SMTPAPI

You can use our SMTPAPI to greatly increase your message throughput. As with SMTP, 100 messages can be sent with each connection, but there can be 1000 'TO:'  recipients for each message using the x-smtpapi header. You can use this option through SMTP sending as well as the Web API v3.

Try opening additional connections

Lastly, you can try to open additional connections from your end. Generally, we recommend a maximum of 10 concurrent connections. However, please note that Twilio SendGrid can handle as much mail as you can throw at us.

One important thing to remember is make certain that the maximum amount of mail is passed before terminating each connection. We recommend using caution when incrementing your number of active connections.

Check your network latency

More often that not, one of the 3 prior suggestions above will resolve a latency problem. However, some latency issues are simply due to the quality of your connection or traffic shaping. It's possibile that your network problem lies with either you or your ISPs configuration. Below are a number of methods that will help you determine where a latency issue really is.

Ping: You should use a ping test to help determine response time and TTL (time to live) in milliseconds. To run a ping test, open a terminal or command prompt window, and then type the following command:

ping smtp.sendgrid.net

Tip: Appending the parameter -t to the end of your ping command on Windows machines will run a continuous ping test. Simultaneously press the control and C keys to end your test.

ping smtp.sendgrid.net
PING smtp.sendgrid.net (13.114.210.107): 56 data bytes
64 bytes from 13.114.210.107: icmp_seq=0 ttl=59 time=25.974 ms
64 bytes from 13.114.210.107: icmp_seq=1 ttl=59 time=22.492 ms
64 bytes from 13.114.210.107: icmp_seq=2 ttl=59 time=24.957 ms
64 bytes from 13.114.210.107: icmp_seq=3 ttl=59 time=22.012 ms
64 bytes from 13.114.210.107: icmp_seq=4 ttl=59 time=24.220 ms
64 bytes from 13.114.210.107: icmp_seq=5 ttl=59 time=22.019 ms
64 bytes from 13.114.210.107: icmp_seq=6 ttl=59 time=22.585 ms
64 bytes from 13.114.210.107: icmp_seq=7 ttl=59 time=33.405 ms
64 bytes from 13.114.210.107: icmp_seq=8 ttl=59 time=32.543 ms
64 bytes from 13.114.210.107: icmp_seq=9 ttl=59 time=45.049 ms
64 bytes from 13.114.210.107: icmp_seq=10 ttl=59 time=25.669 ms
^C
--- smtp.sendgrid.net ping statistics ---
11 packets transmitted, 11 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 22.012/27.357/45.049/6.744 ms

Note: Anything exceeding 150.000 ms should be the first indication that something may be amiss regarding your network connection. Let your IT department know pronto.

 

Hping

1. We'll begin with hping (or Test-NetConnection as a Windows alternative). You should always test hping to help determine response time and TTL (time to live) in milliseconds. In our troubleshooting scenario below, we'll run a hping command to our SMTP server at smtp.sendgrid.net

2. How to run hping: Open “terminal”. Type “sudo hping smtp.sendgrid.net -p 587 -S” and you will see a ping occur continually.

sudo hping smtp.sendgrid.net -p 587 -S
Password:
HPING smtp.sendgrid.net (gpd0 169.45.89.186): S set, 40 headers + 0 data bytes
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=0 win=29200 rtt=40.5 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=1 win=29200 rtt=40.5 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=2 win=29200 rtt=45.7 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=3 win=29200 rtt=42.8 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=4 win=29200 rtt=47.2 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=5 win=29200 rtt=51.8 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=6 win=29200 rtt=42.4 ms
len=44 ip=169.45.89.186 ttl=49 DF id=0 sport=587 flags=SA seq=7 win=29200 rtt=45.2 ms
^C
--- smtp.sendgrid.net hping statistic ---
8 packets tramitted, 8 packets received, 0% packet loss
round-trip min/avg/max = 40.5/44.5/51.8 ms

Note: Anything exceeding 150.000 ms should be the first indication that something may be amiss regarding your network connection. Let your IT department know pronto.

Traceroute: A traceroute test will follow the the path from your computer to SendGrid's servers, displaying each connection and the latency. This allows you to see if there is any latency in your connection to SendGrid. To run a traceroute test, open a terminal window, and then type the following command:

traceroute smtp.sendgrid.net

Tip: Windows users, type tracert smtp.sendgrid.net

traceroute smtp.sendgrid.net
traceroute: Warning: smtp.sendgrid.net has multiple addresses; using 52.220.95.193
traceroute to smtp.sendgrid.net (52.220.95.193), 64 hops max, 52 byte packets
1 www (192.168.1.1) 18.146 ms 2.551 ms 2.114 ms
2 abts-tn-dynamic-001.1.178.122.airtelbroadband.in (122.178.1.1) 13.984 ms 13.460 ms 21.947 ms
3 182.66.79.49 (182.66.79.49) 23.753 ms 17.914 ms
182.66.79.37 (182.66.79.37) 15.524 ms
4 116.119.57.150 (116.119.57.150) 53.598 ms
116.119.68.223 (116.119.68.223) 63.998 ms
182.79.149.246 (182.79.149.246) 88.403 ms
5 52.46.167.158 (52.46.167.158) 100.151 ms 71.591 ms 83.193 ms

 

As with the ping method, keep an eye out for any times over 150.000ms. You'll also want to pay close attention to notice if there are any major increases from one hop to the next. This could indicate the inherent latency from when the packet leaves a server in France en route to a server in Canada. Another flag to watch out for are any of the increases early in the transit, as this could mean the latency lies within your local network, or at a certain ISP.

Additionally, please keep in mind that many modern network nodes will de-prioritize ICMP packets (which traceroute sends), so timeouts at certain hops may not necessarily be indicative of a faulty connection. That said, a traceroute can still go along way in helping isolate where a network issue exists.

Review email headers

Google provides a free header analyzer tool that you can use to analyze the headers of an email, and find out how long an email spent in a particular location. For more information, see How do I check the headers/raw source of an email (SendGrid.com).

 

1. Grab the headers of the message you want to analyze. Make sure you just grab the received headers, which is everything above the first content boundary.

Grabbing headers proccess.2. Paste them into the header analyzer tool and hit the Analyze button.

Pasting the headers into the header analyzer tool

 

The results provided should show the exact journey a message takes from one Mail Transfer Agent to the next, and how long it spent at each one! This tool can be invaluable for figuring out who to "blame" for email delays.

Packet capture and analysis

In cases where ping and traceroute fail to uncover any obvious lag, a TCP dump or packet capture (PCAP) can tell us a lot. This can be helpful for analyzing traffic, filtering TCP streams, and more. When troubleshooting latency issues, the Twilio SendGrid support team may ask you for a PCAP to give us better visibility.

If you're not familiar with this process, we recommend using this helpful guide for collecting packet captures with Wireshark: How to Use Wireshark to Capture, Filter and Inspect Packets (HowtoGeek.com).

Notice: Make sure that the PCAP covers your attempt to send a single message to SMTP.sendgrid.net.

Have more questions? Submit a request