Server providers such as DigitalOcean, AWS, Vultr, and others block your email's outgoing port 25 to stop spam from getting through. However, you can always ask them to unblock it. If you want to find out if your port 25 has been blocked, you can use a manual telnet session to test SMTP connection.
SMTP connection errors can be resolved in a variety of ways, but command line can detect them directly. Telnet is typically used to test SMTP connection failures. In the steps that follow, we will use Telnet to test the email server. A critical part of setting up an email server is making sure SMTP works from the command line (Linux).
Telnet is the most commonly used way to check SMTP from the Command Line. It is also the most common way to test SMTP Relay.
Table of Contents
What is SMTP?
SMTP is a text-based, connection-oriented protocol in which a mail sender connects with a mail receiver by sending command strings and supplying required data across a reliable ordered data stream channel, often a Transmission Control Protocol (TCP) connection.
An SMTP session is made up of commands from an SMTP client (the initiating agent, sender, or transmitter) and responses from an SMTP server (the listening agent, or receiver) that initiate the session and exchange session parameters. There may be zero or more SMTP transactions in a session. Three command/reply sequences make up an SMTP transaction:
- MAIL command, also known as return-path, reverse-path, bounce address, mfrom, or envelope sender, to set the return address.
- To establish a message recipient, use the RCPT command. This command can be repeated as many times as necessary, one for each recipient. The envelope also has these addresses.
- DATA to indicate the start of the message text; the message's content, as opposed to its envelope. It consists of an empty line between a message header and a message body. The server responds twice: first to the DATA instruction itself, acknowledging that it is ready to receive the text, and again after the end-of-data sequence, accepting or rejecting the complete message.
What is a Telnet session?
Telnet is a network protocol for remotely accessing a computer and establishing a two-way, collaborative, text-based communication channel between two computers.
It creates remote sessions using the Transmission Control Protocol/Internet Protocol (TCP/IP) networking protocol, which is controlled by the user. Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP) on the web simply allow users to request specific files from faraway computers, whereas Telnet allows users to log on as a regular user with the privileges assigned to the specific applications and data on that computer.
Telnet is most commonly used by coders and anyone who needs to access certain apps or data on a remote computer.
How does Telnet works?
Telnet is a client-server protocol for opening a command line on a distant computer, usually a server. This utility can be used to ping a port and determine whether it is open. Telnet uses a virtual terminal connection emulator, which is an abstract instance of a computer connection that uses standard protocols to act like a physical terminal attached to a system. For users that need to communicate data files, FTP and Telnet can be utilized together.
Telnet allows users to connect to a machine remotely, often known as Telnetting into the system. They must provide their user credentials combination to gain access to the remote computer, which allows them to run command lines as if they were physically present at the computer. Users' IP addresses will match the computer they are signed in to instead of the one they used to login, regardless of their physical location.
What are the uses of Telnet?
Telnet can be used to do a range of tasks on a server, including file editing, programme execution, and email checking.
Some servers allow remote connections through Telnet to public data in order to play simple games or look for weather forecasts. Many of these features exist because they are nostalgic or because they are still compatible with earlier systems that require certain data.
Telnet also allows users to connect to any software that uses text-based, unencrypted protocols, such as web servers and ports. Users can open a cmd on the remote machine and type telnet followed by the name or IP address of the remote machine, and the telnet session will ping the port to see whether it is open or not. A blank screen indicates that the port is open, but an error message indicating that the port is connected indicates that it is closed.
Security in Telnet
Telnet is a non-secure, unencrypted protocol. Anyone can view a user's username, password, and other confidential information typed in plaintext during a Telnet session by monitoring the user's connection. This information can be used to gain access to the targeted computer.
Test SMTP connection using Telnet
We will first run some tests to see if your outgoing port 25 is opened or not, in first case we will demonstarate a blocked SMTP port 25 in second case we will go through by sending an email using telnet.
Case 1: Port 25 Blocked
On command line run the following command (you need to run this command on a server you are having email problems):
telnet <IP_ADDRESS_OF_REMOTE_MAIL_SERVER> 25
If you are receiving a message like "TRYING ..." and nothing else that means your outgoing port 25 is blocked and you wont be able to send email messages from your server.
Case 2: When port 25 is opened:
We need to find a mail server to log into if you don't have the IP address of mail server. For this, we will need the DNS MX record for a given domain. This can be found with the following command
nslookup -type=mx DOMAIN_NAME
SMTP employs one of three ports: 25, 465, or 587, which are often used by Microsoft Outlook. If your SMTP relay uses a port other than 25, you'll utilize the port supplied in the nslookup response from the mail exchange server. You can either ask your administrator or go into the mail exchange server and look at the protocols to see what port your SMTP uses.
To log in to the SMTP server:
telnet <IP_ADDRESS_OF_MAIL_SERVER> <PORT>
If your connected, you can continue with sending emails
The EHLO or HELO command is the first command we need to send to the mail server for our SMTP email tester. This is a simple welcome that begins the telnet client's conversation with the SMTP server.
The SMTP commands that the SMTP server accepts are displayed here.
The MAIL FROM command is the next command we really have to run. The address to which bounces are sent is determined by this.
MAIL FROM: <[email protected]>
We can now send the RCPT TO command after the MAIL FROM command has been issued. This command instructs the SMTP mail server to send the message to the specified recipient.
RCPT TO: <[email protected]>
The DATA command is the last command to run before commencing the message body. This command informs the SMTP mail server that the rest of the message will be transmitted as the body of the message.
Enter Subject: <SUBJECT> and press Return.
Enter <Test message> and press Return.
When the message is finished, we must inform the SMTP server that we are finished with it and that we want the SMTP mail server to accept it. This is accomplished by placing a period on a single line. If a period on a single line is required while writing a message, use two periods, the first escaping the second.
The message OK will appear, followed by an ID code. Your message has been delivered.
Return to the Telnet window, enter quit to terminate the SMTP server connection, and then quit to terminate the Telnet session.
What is SMTP connection testing?
SMTP connection testing involves checking the connection between your email server and the recipient's server to ensure smooth email delivery. It helps identify issues that might prevent emails from being sent or received.
How do I test SMTP connection settings?
To test SMTP connection settings, you can use various tools or command-line utilities. One common method is using the "telnet" command in your terminal to establish a connection to the SMTP server and simulate an email transfer.
What is the purpose of testing SMTP connectivity?
Testing SMTP connectivity ensures that your email server can communicate effectively with other servers, reducing the chances of emails being marked as spam or not reaching their intended recipients.
What are the steps to perform SMTP connection testing?
Start by obtaining the SMTP server address and port number. Then, use tools like "telnet" or specialized SMTP testing software. Initiate a connection, simulate an email transfer, and verify if the process completes without errors.
What do I do if my SMTP connection test fails?
If the test fails, double-check the server address, port, and any authentication details. Ensure your server's firewall allows outbound connections on the specified port. Review the error messages to troubleshoot the issue.
Are there online tools for testing SMTP connections?
Yes, there are online tools that allow you to test SMTP connections by entering server details. These tools simulate the connection and provide feedback on the success or failure of the test.
If you complete the test, you can be certain that there is nothing wrong with your email server or the address and information you used to get access to it.
If the SMTP server informed you that the origin email address was invalid, it's possible that you typed it incorrectly. It's also possible that something is wrong with your email account, which is why you can't get it to work in your new email client.
Hopefully, testing your SMTP server via Telnet while away from your new email client will help you narrow down all of the possible causes for any email issues you're having.