Whenever you are in development mode you might face challenges to send emails OR Sometimes it happens your SMTP relay service suddenly stops working. Let see how to troubleshoot SMTP relay server.
Below are some of the errors which you might see often:
IO::Socket::INET6: connect: timeout
535: 5.7.8 Error: authentication failed
421 4.7.1: Sender address rejected
Below are steps for troubleshooting your SMTP relay
- OS – Linux
- Any Terminal for CLI
- You SMTP Relay Details
Let’s assume you are using the below test configuration for SMTP Relay to send an email.
SMTP Host: smtp.mail250.com SMTP Username: mail250 SMTP Password: Pass@123 SMTP Port: 25 From: firstname.lastname@example.org To: email@example.com
Below is complete troubleshoot steps:
1. PING: Check your Internet connection & SMTP server connection
$ ping smtp.mail250.com
PING smtp.mail250.com (18.104.22.168) 56(84) bytes of data. 64 bytes from 22.214.171.124 (126.96.36.199): icmp_seq=1 ttl=52 time=27.4 ms 64 bytes from 188.8.131.52 (184.108.40.206): icmp_seq=2 ttl=52 time=26.5 ms 64 bytes from 220.127.116.11 (18.104.22.168): icmp_seq=3 ttl=52 time=25.1 ms
If you getting the Above output, Which means your internet connection working and packets are receiving by SMTP Relay server.
But if you are unable to get such output then try to ping another domain.
$ ping google.com PING google.com (22.214.171.124) 56(84) bytes of data. 64 bytes from bom05s08-in-f14.1e100.net (126.96.36.199): icmp_seq=1 ttl=57 time=2.43 ms 64 bytes from bom05s08-in-f14.1e100.net (188.8.131.52): icmp_seq=2 ttl=57 time=2.36 m
If it’s getting the same output then you can make sure that something is wrong on SMTP relay server. If you gets something like “Request timed out“, Then there is nothing that you can do on your side. You have to reach your SMTP relay service provider.
If Domain is invalid you will get below error :
ping: smtp.mail250.co.in: Name or service not known
You can also try these all commands from here https://ping.eu/ping/
Note: There are chances that the ping command is disabled on the remote server. So you will not get any results.
2. TELNET: Check whether you can connect to PORT 25?
$ telnet smtp.mail250.com 25
Trying 184.108.40.206... Connected to smtp.mail250.com. Escape character is '^]'.
If you getting above output, Then yes you can connect PORT 25.
But you can get below errors too:
SMTP -> ERROR: Failed to connect to server: Permission denied
There are chances, SELINUX is running on your system. SELinux is preventing to send emails from webservers OR PHP. This usually running on cloud servers like Digitaloccean.
You can check whether your httpd daemon is allowed to make a connection over the network and send an email using ‘getsebool‘ command.
$ getsebool httpd_can_sendmail $ getsebool httpd_can_network_connect
This command will return a boolean on or off. If it’s off, we can turn it on:
$ sudo setsebool -P httpd_can_sendmail 1 $ sudo setsebool -P httpd_can_network_connect 1
In the case of PHP-FPM, You need to apply this to fpm daemon.
telnet: Unable to connect to remote host: Connection refused
There is a possibility, SMTP Relay host itself not allow to connect on PORT 25.
There is a chance your firewall is not allowing to connect destination port 25.
You can make sure by connecting other SMTP relay server like below:
$ telnet smtp.gmail.com 25 Trying 220.127.116.11... Connected to smtp.gmail.com. Escape character is '^]'. 220 smtp.gmail.com ESMTP a5sm740325pjh.7 - gsmtp
If it succeeds in connecting with other SMTP Relay server then we can confirm that something is wrong with our SMTP Relay.
If it still not works, there is nothing left to do anything on your side. You should check with your SMTP relay service provider.
3. Cross-check Credentials: Check with SMTP Username & Password
Make sure you are using a proper configuration like SMTP username & SMTP password. Usually, it will generate “Error: authentication failed” when there is something wrong with your credentials.
4. Sender address rejected: Something wrong with From Address
Below are some “Sender address rejected” messages, Which you might get frequently.
421 4.7.1: Sender address rejected: Account disabled
As mentioned in the message “Account disabled“, The from Address by which you are sending emails, It is mapped with some account on SMTP Relay server or provider (Mostly the account is the same which is your SMTP username). This account is disabled by your SMTP provider OR It is restricting you to send emails by this account. In such case mostly all email gets restricted which is going by this particular account.
450 4.1.8: Sender Address Rejected: Domain Not Found
This type of error occurs when your From Domain is not able to resolve (DNS resolve) properly. For example your domain don’t have valid MX / A record etc, Nameserver are not responding.
Sometimes when you make DNS changes it takes time to reflect all over the internet (Mostly on nameservers) which can cause this error. The receiving server cannot recognize or verify your domain.
You can verify this type of details from https://mxtoolbox.com/
553 5.7.1: Sender address rejected: not owned by user
This type of error usually occurs when you are trying to send emails from that domain which is not associated with your mentioned account. In such case you need to whitelist / Add your domain in this account and Then only you are allow to send emails.
Some SMTP relay providers verify your domain with their criteria and then they allow you to send an emails.
554 5.7.1: Sender address rejected: Access denied
This type of error occurs when you have invalid credentials OR You are trying to reach SMTP relay server without authentication. You must authenticate your SMTP call by passing SMTP Username & Password and it should be correct.
If you set the wrong MX record in your sender domain, Then also you can get this error.
Spam Filter Errors
554 5.7.1 : Message cannot be accepted, spam rejection
Some SMTP Relay providers have their own filters, Which parse your email content & Subject line And It tries to detect whether it looks like Spammy or not. If it detected positive then it can throw such errors.
554 5.7.1 : Message cannot be accepted, rules rejection
Some SMTP Relay put some rules on their end. Which evaluate on every email.
554 5.7.1 : Message refused by Dictionary check
SMTP Relay Service provider has some set of words which marked as SPAM. There is chances your email content can contains such Spammy words.
Below is some Error which can occur because of above-specified reasons:
554 5.7.1 : The message from (<firstname.lastname@example.org>) with the subject of (…) matches a profile the Internet community may consider spam. Please revise your message before resending.
554 5.7.1 : Email cannot be delivered. Reason: Email detected as Spam by spam filters.
554 5.7.1 : [MW01] Message content not accepted for policy reasons
554 5.7.1: Service unavailable; Client host X.X.X.X blocked using zen.spamhaus.org
The IP by which your SMTP Relay service sending emails is got Blacklisted on “zen.spamhaus.org“. You can check on Blacklistmaster Whether your domain is blacklisted anywhere or not.
Similarly your domain can get blacklisted on any of DNSBL.
Block by Recipient Server (Gmail, Yahoo etc.)
554 5.7.1 : You are not allowed to connect
Here Recipient SMTP server is not allowing the sender SMTP relay server to connect. This mostly happens when the SMTP relay server tries to send emails from dynamic IPs. Also possible your sender IP is get blacklisted which will cause this error.
Email account not exists
554 5.7.1: <email@example.com>: Sender address rejected: testdomain.com is not allowed to send email to mydomain.com
This type of error occurs when you try to send an email on an invalid address Or The recipient address which does not exist.
5. Verify your SMTP Details & Change PORT
Verify you are all SMTP Details like SMTP Host, Port & From Address. Usually, Ports are reserved for the special use case, click here to know more what smtp port you should use.
Below are the Ports which you can use.
25 – Default SMTP PORT
465 – SSL Connection
587 – TLS Connection
2525 – An alternative port of 587
You can simply give a try just changing your port.
6. Send Test email with SWAKS
You can just install the swaks CLI tool https://www.jetmore.org/john/code/swaks/ to make a test email.
swaks --server smtp.mail250.com:25 \ --auth-user mail250 \ --auth-password Pass@123 \ --to firstname.lastname@example.org \ --from email@example.com
It will show you all error on screen itself.
This is how you can troubleshoot your SMTP relay server/service. Keep checking this article, I will keep updating.
If you guys facing some new error which is not mention in this blog, Feel free to comment below. We will try our best to help you 🙂