SMTP (Simple Mail Transfer Protocol)

Port: 25, 465, 587
Type: Email Delivery

Description

SMTP is the core protocol responsible for sending emails across the internet. It operates as a push-based protocol meaning that email servers actively send messages to the next server in the delivery chain. SMTP was originally designed without encryption or authentication and because of this early versions were vulnerable to spoofing and interception. Modern implementations solve these problems through security extensions and encrypted communication channels. Despite alternative mail protocols existing SMTP remains the backbone of email transmission worldwide.

Technical Details

  • Uses port 25 for server to server communication.
  • Uses port 465 for SMTP over SSL and port 587 for SMTP with STARTTLS.
  • Operates through text based commands such as HELO MAIL FROM RCPT TO and DATA.
  • Uses a store and forward mechanism for message transfer.
  • Supports authentication mechanisms through SMTP AUTH extensions.

How To Work

SMTP begins working when an email client or service prepares a message for delivery. The client connects to an SMTP server on port 25 or one of the secure alternatives like 465 or 587. This connection establishes the initial communication channel through which all commands and responses will be exchanged.

Once the connection is established the client starts by sending either a HELO or EHLO command. HELO is the older version while EHLO supports additional features such as authentication and encryption upgrades. The server replies with a greeting message and a numeric status code that indicates whether the communication can proceed.

After the greeting phase the client may need to authenticate depending on server configuration. Authentication is performed through mechanisms like LOGIN PLAIN or more secure options such as CRAM MD5. If STARTTLS is supported the client can upgrade the plain text connection to an encrypted one before sending sensitive credentials.

Once authentication is complete the client specifies the sender address using the MAIL FROM command. The server validates this address and responds with a status code. If the address is acceptable the client then issues one or more RCPT TO commands to list the intended recipients. The server checks each address and confirms whether delivery is allowed.

When the server accepts at least one recipient the client sends a DATA command. This signals the transition from command mode to data mode. The server replies with a prompt indicating it is ready to receive the message body. The client then transmits the email header fields and text content ending the data section with a single period on its own line.

Upon receiving the complete message the SMTP server attempts to deliver it. If the recipient belongs to the same server the message is stored locally. If the recipient is external the server queries DNS for MX records to determine which server is responsible for the target domain. The message is then forwarded using another SMTP session.

If delivery to the next server fails SMTP uses a queue based retry mechanism. Emails may be deferred temporarily if the destination server is unavailable. Automatic retry attempts continue for a predetermined period often up to several days before the message is considered undeliverable.

Throughout the entire process both the client and server exchange status codes that describe the current state. These codes help identify issues such as authentication failures mailbox unavailability or server side errors. Administrators rely heavily on these codes when diagnosing email delivery problems.

Once all message transfers are complete the client sends a QUIT command. This instructs the server to close the session gracefully. The server responds with a final acknowledgement and terminates the connection.

Logs play a crucial part in SMTP operations. Every step including authentication attempts message transfers errors and recipient responses is recorded. These logs are invaluable for security monitoring performance analysis and troubleshooting complex delivery issues.

Security Considerations

SMTP by itself provides no encryption and supports spoofable sender addresses. Attackers can intercept messages or impersonate legitimate users. This is why modern servers enforce TLS authentication and anti spoofing technologies such as SPF DKIM and DMARC. These protections reduce spam and prevent unauthorized senders from forging email identities.

Potential Abuse Cases

Open SMTP relays can be hijacked to distribute massive amounts of spam. Weak authentication can allow attackers to send phishing emails from legitimate domains. Compromised servers can be used to forward malicious attachments or participate in botnet controlled campaigns. Misconfigured DNS records can also be exploited to bypass verification mechanisms.

Detection Strategies

Monitoring failed login attempts and unusual sender patterns is critical for detection. Large volumes of outgoing emails may indicate spam activity. Log analysis tools can detect spoofing attempts or unauthorized relay usage. IDS and mail security gateways can inspect SMTP traffic for suspicious attachments and command patterns.

Mitigation Techniques

Enforcing TLS and strong authentication is essential. Administrators should disable open relays and restrict which IP addresses can send mail through the server. SPF DKIM and DMARC must be configured to protect domain identity. Rate limiting and content filtering can reduce abuse and block suspicious emails before delivery.

References