The Simple Mail Transfer Protocol (SMTP) is a communication protocol used for sending email messages between servers over the internet. It is a set of rules that allows two hosts to communicate and exchange email messages.
SMTP operates on two primary models – it initiates communication between a mail client and a mail server to send an outgoing message, and it enables communication between two mail servers to route email on the internet.
How SMTP Works
When you send an email from your email client (Outlook, Thunderbird etc), here is a simplified version of what happens behind the scenes:
- Your mail client connects to your organization’s mail server using SMTP and sends the outgoing email.
- Your mail server adds header information to the message including content such as sender, receiver, subject etc.
- The mail server then connects to the recipient’s mail server using SMTP and sends the email across.
- The recipient mail server receives the message and stores it until the recipient downloads it using protocols like IMAP or POP3.
So in summary, SMTP handles the conversation between mail servers to route the mail across while other protocols help clients send and receive messages from the mail server.
Components in an SMTP Transaction
Here are the key components in an SMTP transaction:
- User Agent: The mail client which initiates the SMTP connection. e.g. Thunderbird, Outlook.
- Mail Transfer Agent (MTA): The mail servers which communicate using SMTP to send and relay messages.
- SMTP Commands and Replies: The command and response codes used to indicate status and direct the flow of the SMTP conversation.
Key Features of SMTP
- Simple text-based communication for sending email messages between hosts.
- Client-server model – Enables user agents to send mail to mail server.
- Support for relaying email via multiple hops – Messages can be relayed between multiple intermediate mail servers to reach destination.
- Uses TCP port 25 for communication by default.
- Has various commands to initiate session, send sender/recipient data etc which returns response codes indicating status.
Example SMTP Transaction
Here is an example SMTP communication session between a client and server to send an email:
- Client initiates session
CLIENT: 220 mail.example.com ESMTP Service Ready
SERVER: EHLO client.example.org
- Server responds that client can send mail
SERVER: 250 Accepted
- Client provides sender mail ID
CLIENT: MAIL FROM: [email protected]
SERVER: 250 OK
- Client provides recipient mail ID
CLIENT: RCPT TO: [email protected]
SERVER: 250 Accepted
- Client initiates mail body
SERVER: 354 Send Message Data
CLIENT: From: [email protected]
Subject: Test SMTP mail
This is a test mail to check SMTP working.
SERVER: 250 OK Message Accepted
- Client terminates session
SERVER: 221 Service Closing Connection
In this simplified transaction, we see the client opening connection, providing sender recipient details, sending the mail body content, and finally terminating the session. The server provides response codes during each step indicating whether the command was accepted.
Common SMTP Ports
- Port 25 – Default port used for SMTP communication
- Port 465 – SMTP over SSL encryption
- Port 587 – SMTP with authentication
- Port 2525 – Alternative SMTP port
Using alternative ports help get around ISP restrictions sometimes placed on port 25 to reduce spam. Ports 465 and 587 enable encryption and authentication capabilities as well.
SMTP Security Considerations
Some security aspects to note regarding SMTP:
- Communication using plain text – Messages are unencrypted and human-readable.
- No built-in user authentication – No identity verification before relaying messages.
- Open for abuse without additional security – Spammers/attackers can use it to send mail anonymously.
To address this, modern mail servers support additional SMTP extensions for encryption using SSL/TLS and authentication protocols like SMTPS and SMTP AUTH to validate user identity when sending and receiving mail between servers.
- SMTP handles communication between mail servers to help route emails across the internet.
- Clients use SMTP to send mails to their mail server, which uses SMTP again to relay it to the recipient’s mail server.
- Key steps include handshake, providing envelope information, sending mail body, getting response codes from server.
- Common ports – 25, 465 (SSL), 587 (authentication)
- Security limitations of plain text transfer can be addressed by encryption and authentication mechanisms.
In summary, SMTP is a long-established protocol that enables routing of emails and communication between mail servers on the internet. Understanding how a basic SMTP transaction works helps clarify exactly how our email travels from a client to multiple servers across networks before ending up in the recipient’s inbox. Additional security mechanisms have further extended SMTP’s capabilities around authentication and encryption to close some gaps while retaining email as a simple, lightweight, and ubiquitous communication mechanism globally.
Frequently Asked Questions
- What is SMTP stand for?
SMTP stands for Simple Mail Transfer Protocol. It is a communication protocol used for transmitting email messages between servers over the internet.
- Which port does SMTP use?
SMTP commonly uses port 25 for unencrypted communication. Ports 465 and 587 are also sometimes used – 465 for SMTP over SSL and 587 for SMTP with user authentication.
- Is SMTP secure?
By itself, SMTP has no encryption and sends messages in plain text. This allows emails to be intercepted easily. To make it secure, extensions like SMTPS (over SSL) are used to encrypt connections.
- What is the difference between SMTP and POP3 or IMAP?
SMTP handles sending emails and communication between mail servers. POP3 and IMAP are used by client mail applications to retrieve messages from the mail server to your local mailbox.
- What are SMTP commands?
SMTP commands are used to initiate a mail sending session and transfer messages between servers. Examples include HELO, MAIL FROM, RCPT TO, DATA (for message content) and QUIT.
- What is an SMTP header?
An SMTP header contains metadata about the email message like sender’s address, receiver’s address, subject line etc. which is sent during the SMTP transaction before the actual message body.
- Can I send emails without an ISP using SMTP?
Yes, you can install an SMTP server and connect to it from an email client to directly send mails without going through an ISP’s SMTP server. Services like Amazon SES also offer this capability.
- What are SMTP response codes?
SMTP response codes indicate the status of each command sent during an SMTP conversation. For example, 220 indicates the server is ready, 250 means request actions successful, 354 signals to start mail body.
- Can I use Gmail SMTP server to send emails?
Yes, Gmail provides SMTP servers via port 465 (SSL) and 587 (TLS) which can be configured in external mail clients to send mails by authenticating via your Gmail/Google Workspace login.
- How does SMTP differ from webmail?
Webmail sends emails using back-end SMTP servers. The main difference is SMTP is directly exposed for machine-to-machine communication while webmail provides an interactive front-end interface to users.
- Is SMTP faster than webmail?
In most cases, SMTP provides faster mail delivery than webmail as it establishes more persistent connections directly between sending and receiving servers instead of an intermediate HTTP layer.
- What tools can interact with SMTP servers?
Some common tools used to interact with SMTP servers include mail clients like MS Outlook and Thunderbird, command line tools like Telnet, libraries for various programming languages, automation tools, mail testing tools like Mail-Tester, and more.
- How to check if an SMTP server is working correctly?
Try establishing a connection via Telnet on ports 25, 465 or 587. Send SMTP commands and check if you get appropriate response codes back according to the protocol. Test with test accounts or actual mail accounts for further testing.
- Can I relay mails between multiple SMTP servers?
Yes, mail relaying is a key part of how SMTP enables routing emails between multiple machines – from your local network’s mail server to your ISP’s primary server to the recipient mail server and others in between.
- How is SMTP different from HTTP protocol?
While HTTP powers the web, enabling browser-server connections, SMTP routes mails between servers across the internet. HTTP uses port 80 while SMTP uses port 25 primarily. HTTP is for external users while SMTP is machine-oriented.
- Why I am unable to send mails to some domains at times?
This can happen due to incorrect DNS records, relisting that temporarily rejects unknown servers, invalid recipient addresses, spam filters flagging content, or the recipient server being unavailable/down.
- What security checks should be done on an SMTP server?
Scanning for open relays to prevent abuse, implementing TLS encryption, using SMTP AUTH for valid credentials to send mail, enabling domain keys/DKIM for domain-identity validation, deploying appropriate firewall rules, and more.
- What are some alternatives to SMTP for enterprises?
Some alternatives used by large enterprises include Send mail, IBM Domino, Microsoft Exchange Server, Lotus Notes, Novell GroupWise – which incorporate additional features around security, reliability and performance.
- Can I change the default SMTP port 25 to something else?
Yes, the TCP port used for SMTP can be changed. Common alternatives include ports 2525, 8025 or 1025. This helps resolve port 25 blocking issues for outbound mails in some networks. Just ensure both sending and receiving servers use the same non-standard port.
- What are best practices when running an SMTP server?
Some best practices include blocking unused dangerous SMTP extensions, enabling SMTP AUTH before accepting messages, rejecting poorly formed addresses to counter DOS attacks, activating TLS encryption, establishing DKIM/domain keys for trust, enabling rate limiting, isolating mail subnet in DMZ, and more.