SMTP - Simple Mail Transfer Protocol ====================================== .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is SMTP?** SMTP stands for Simple Mail Transfer Protocol. It is a standard communication protocol used to send emails from one server to another over the internet. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why is SMTP useful?** * Enables email delivery between different email servers (e.g., from Gmail to Outlook). * Supports authentication and encryption to secure email transmission. * Works with other protocols like IMAP and POP3 to complete the email lifecycle (sending + receiving). * Widely supported by all major email clients and services. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How it works?** * User sends an email using an email client (like Outlook or Gmail). * The email client connects to the SMTP server and sends the message. * The SMTP server processes the message and determines the recipient’s domain. * It forwards the email to the recipient’s mail server (using DNS to find it). * The recipient’s server stores the email, ready to be fetched by the user via IMAP or POP3. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Where is SMTP used?** * Email clients (e.g., Outlook, Thunderbird, Apple Mail). * Mail servers (e.g., Microsoft Exchange, Postfix, Sendmail). * Webmail services (e.g., Gmail, Yahoo Mail, Zoho). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why OSI Layer: Application Layer (Layer 7)?** * It defines email commands (HELO, MAIL FROM, RCPT TO, DATA, etc.). * It interacts with user-facing applications (e.g., Outlook, Gmail). * It handles message formatting and transfer logic, not data transport or routing. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the key features?** * Outbound Email Protocol * Text-Based Protocol * Supports Authentication (SMTP AUTH) * Port Flexibility .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is an SMTP server?** A server that: * Accepts outgoing email. * Relays email to destination servers. * Examples: Sendmail, Postfix, Exim, Microsoft Exchange, Gmail SMTP. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a mail relay in SMTP?** A mail relay is when an SMTP server forwards email from one domain/server to another. Used in: * Email routing between domains. * Sending mail from client to provider’s SMTP. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Can SMTP be used over IPv6?** Yes. SMTP works over both IPv4 and IPv6 as long as the DNS records and mail servers support it. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are some applications that use SMTP?** * Email Clients * Webmail Services * Web Applications & Contact Forms * Command-Line Tools & Scripts .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the working flow of SMTP?** * **User Composes Email** * You write an email in a mail client (e.g., Outlook, Gmail, Thunderbird). * Click “Send”. * **Mail Client Connects to SMTP Server** * The client connects to the SMTP server on port: * 587 (with STARTTLS encryption – most common) * 465 (SSL/TLS) * 25 (for server-to-server) * **Client Authenticates** * The mail client logs in using: * Username and password * Uses AUTH LOGIN or AUTH PLAIN commands * **Email Envelope is Sent** * The client sends: * `MAIL FROM:` – sender's email address * `RCPT TO:` – recipient’s email address * **Message Content is Sent** * The client sends: * `DATA` command * Followed by the email body, subject, headers, and attachments (in MIME format) * Ends with a single dot `.` on a new line to finish the message * **Email is Queued or Relayed** * The SMTP server either: * Delivers the email locally, or * Looks up recipient’s domain via DNS (MX record) and relays the message to the recipient’s mail server * **Recipient Server Accepts the Mail** * The recipient mail server stores the email in the user's inbox. * The recipient will later fetch it using POP3 or IMAP. * **Client Sends QUIT** * The SMTP session ends with the `QUIT` command. * The server closes the connection. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are common SMTP server software options?** * Postfix – Linux * Sendmail – Linux/Unix * Exim – Linux * MailEnable – Windows * hMailServer – Windows .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is SMTP Windows specific?** * No, SMTP (Simple Mail Transfer Protocol) is **not Windows-specific**. * It is a **cross-platform protocol** and works on Windows, macOS, Linux, and other systems. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is SMTP Linux specific?** * No, SMTP is **not Linux-specific**. * It is widely supported across various platforms and operating systems. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Transport Protocol is used by SMTP?** * SMTP uses the **Transmission Control Protocol (TCP)** to ensure reliable message delivery. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Port is used by SMTP?** * SMTP typically uses: * **Port 25** for standard message transfer (may be blocked by ISPs to prevent spam) * **Port 587** for message submission (with STARTTLS encryption) * **Port 465** for SMTP over SSL/TLS (SMTPS) .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is SMTP using client-server model?** * Yes, SMTP uses a **client-server model**. * The **client (email-sending application)** connects to the **server (SMTP server)** to send emails to recipients or forward them to other mail servers. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Terminology ` * :ref:`Version Info ` * :ref:`SMTP Version&RFC Details ` * :ref:`SMTP Basic Setup on Ubuntu using IPv4 ` * :ref:`SMTP Basic Setup on Ubuntu using IPv6 ` * :ref:`SMTP Protocol Packet Details ` * :ref:`SMTP Usecases ` * :ref:`SMTP Basic Features ` * :ref:`SMTP Feature : Text Based Protocol ` * :ref:`SMTP Feature : Client Server Architecture ` * :ref:`SMTP Feature : Store and Forward Mechanism ` * :ref:`SMTP Feature : Port Based Communication ` * :ref:`SMTP Feature : Command Set Feature ` * :ref:`SMTP Feature : Encryption Support ` * :ref:`SMTP Feature : Interoperability ` * :ref:`SMTP Feature : Support For Authentication ` * :ref:`SMTP Feature : Header And Body Seperation ` * :ref:`SMTP Feature : Reliable Delivery ` * :ref:`Reference links ` .. _SMTP_step1: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. _SMTP_step2: .. tab-set:: .. tab-item:: Terminology * Terminology .. _SMTP_step3: .. tab-set:: .. tab-item:: Version Info * Version Info .. _SMTP_step5: .. tab-set:: .. tab-item:: SMTP Version&RFC Details .. csv-table:: :file: ./SMTP/SMTP_RFC.csv :widths: 1,10,10,10,30 :header-rows: 1 .. _SMTP_step20: .. tab-set:: .. tab-item:: SMTP Basic Setup on Ubuntu using IPv4 **SMTP Server Setup Test Case (IPv4)** * This test verifies the basic configuration of a Postfix SMTP server over IPv4. It ensures a client can connect using Telnet and send an email via SMTP manually. * Server IP: 192.168.56.10 * Client IP: 192.168.56.11 * Protocol: SMTP (port 25) * Step-1: Install and Configure Postfix on Server (192.168.56.10) Update system packages: .. code-block:: shell test1:~$ sudo apt update && sudo apt upgrade -y Install Postfix: .. code-block:: shell test1:~$ sudo apt install postfix -y During installation: - Choose **Internet Site** - Set system mail name (e.g., `mail.localdomain`) Configure Postfix main settings: .. code-block:: shell test1:~$ sudo nano /etc/postfix/main.cf Ensure the following lines are configured: myhostname = mail.localdomain myorigin = /etc/mailname mydestination = localhost, localhost.localdomain, mail.localdomain inet_interfaces = all inet_protocols = ipv4 mynetworks = 192.168.56.0/24, 127.0.0.0/8 relay_domains = - `mynetworks`: defines trusted clients allowed to relay mail - `inet_interfaces = all`: listens on all interfaces - `inet_protocols = ipv4`: restricts to IPv4 only Restart Postfix to apply changes: .. code-block:: shell test1:~$ sudo systemctl restart postfix * Step-2: Allow SMTP Port Through Firewall Allow SMTP through `ufw`: .. code-block:: shell test1:~$ sudo ufw allow 25/tcp test1:~$ sudo ufw enable * Step-3: Test SMTP Connection from Client (192.168.56.11) Install Telnet: .. code-block:: shell test2:~$ sudo apt install telnet -y Connect to the SMTP server: .. code-block:: shell test2:~$ telnet 192.168.56.10 25 220 mail.localdomain ESMTP Postfix Send test email manually using SMTP commands: HELO client.localdomain MAIL FROM: RCPT TO: DATA Subject: Test Email This is a test email sent via Postfix SMTP server. . QUIT * Step-4: Verify Mail Delivery on Server Check Postfix mail queue: .. code-block:: shell test1:~$ mailq Monitor mail logs: .. code-block:: shell test1:~$ sudo tail -f /var/log/mail.log * Expected Results: - SMTP server responds to telnet session - Client can send mail using manual SMTP commands - Mail is accepted and queued for delivery - Logs confirm mail transaction * Step-5: Wireshark Capture. :download:`Download Wireshark capture ` .. _SMTP_step21: .. tab-set:: .. tab-item:: SMTP Basic Setup on Ubuntu using IPv6 **SMTP Server Setup Test Case (IPv6)** * This test verifies the configuration of a Postfix SMTP server over IPv6. It ensures clients in the IPv6 subnet can connect to the server on port 25 and send mail manually via Telnet. * Server IPv6: fd00:56::10 * Client IPv6: fd00:56::11 * Protocol: SMTP (port 25) * Step-1: Install and Configure Postfix on Server (fd00:56::10) Update system packages: .. code-block:: shell test1:~$ sudo apt update && sudo apt upgrade -y Install Postfix: .. code-block:: shell test1:~$ sudo apt install postfix -y During installation: - Choose **Internet Site** - Set system mail name as `mail.localdomain` (or any hostname) Configure Postfix for IPv6: .. code-block:: shell test1:~$ sudo nano /etc/postfix/main.cf Ensure the following lines are configured: .. code-block:: none myhostname = mail.localdomain myorigin = /etc/mailname mydestination = localhost, localhost.localdomain, mail.localdomain relayhost = mynetworks = [fd00:56::]/64, [::1]/128 inet_interfaces = all inet_protocols = ipv6 relay_domains = - `mynetworks`: allows relay access from the local IPv6 subnet and localhost - `inet_protocols = ipv6`: ensures Postfix only listens on IPv6 interfaces Restart Postfix to apply changes: .. code-block:: shell test1:~$ sudo systemctl restart postfix * Step-2: Allow SMTP Port for IPv6 on Firewall Open TCP port 25 for IPv6 SMTP traffic: .. code-block:: shell test1:~$ sudo ufw allow proto tcp from fd00:56::/64 to any port 25 test1:~$ sudo ufw reload * Step-3: Test SMTP Connection from Client (fd00:56::11) Install Telnet: .. code-block:: shell test2:~$ sudo apt install telnet -y Connect to the SMTP server using IPv6: .. code-block:: shell test2:~$ telnet fd00:56::10 25 220 mail.localdomain ESMTP Postfix Send test email manually using SMTP commands: HELO client.localdomain MAIL FROM: RCPT TO: DATA Subject: Test Email This is a test email sent over SMTP. . QUIT * Step-4: Verify Mail Delivery on Server Check mail queue: .. code-block:: shell test1:~$ mailq Monitor Postfix logs: .. code-block:: shell test1:~$ sudo tail -f /var/log/mail.log * Expected Results: - Client connects to SMTP server using IPv6 - Server responds with a proper SMTP greeting - Email is accepted and queued/delivered - Logs reflect successful mail transaction * Step-5: Wireshark Capture. :download:`Download Wireshark capture ` .. _SMTP_step6: .. tab-set:: .. tab-item:: SMTP Protocol Packet Details **SMTP COMMAND LINE Packet** .. csv-table:: :file: ./SMTP/SMTP_Command_Line_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **SMTP RESPONSE LINE Packet** .. csv-table:: :file: ./SMTP/SMTP_Response_Line_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **SMTP MESSAGE HEADER Packet** .. csv-table:: :file: ./SMTP/SMTP_Message_Header_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **SMTP MESSAGE BODY Packet** .. csv-table:: :file: ./SMTP/SMTP_Message_Body_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **SMTP END Of Data Marker Packet** .. csv-table:: :file: ./SMTP/SMTP_End_of_Data_Marker_Packet.csv :widths: 10,20,30,10 :header-rows: 1 .. _SMTP_step7: .. tab-set:: .. tab-item:: SMTP Usecases .. csv-table:: :file: ./SMTP/SMTP_Use_Cases.csv :widths: 10,20,30 :header-rows: 1 .. _SMTP_step8: .. tab-set:: .. tab-item:: SMTP Basic Features .. csv-table:: :file: ./SMTP/SMTP_Features.csv :widths: 10,10,30 :header-rows: 1 .. _SMTP_step9: .. tab-set:: .. tab-item:: SMTP Feature : Text Based Protocol **Text Based Protocol - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature1_Text_Based_Protocol_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step10: .. tab-set:: .. tab-item:: SMTP Feature : client Server Architecture **Client Server Architecture - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature2_Client_Server_Architecture_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step11: .. tab-set:: .. tab-item:: SMTP Feature : Store And Forward Mechanism **Store And forward Mechanism - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature3_Store_and_Forward_Mechanism_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step12: .. tab-set:: .. tab-item:: SMTP Feature : Port Based Communication **Port Based Communication - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature4_Port_Based_Communication_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step13: .. tab-set:: .. tab-item:: SMTP Feature : Command Set Feature **Command Set Feature - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature5_Command_Set_Feature_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step14: .. tab-set:: .. tab-item:: SMTP Feature : Encryption Support **Encryption Support - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature6_Encryption_Support_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step15: .. tab-set:: .. tab-item:: SMTP Feature : interoperability **interoperability - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature7_Interoperability_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step16: .. tab-set:: .. tab-item:: SMTP Feature : Support For Authentication **Support For Authentication - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature8_Support_for_Authentication_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step17: .. tab-set:: .. tab-item:: SMTP Feature : Header And Body Seperation **Header And Body Seperation - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature9_Header_and_Body_Separation_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step18: .. tab-set:: .. tab-item:: SMTP Feature : Reliable Delivery **Reliable Delivery - Testcases** .. csv-table:: :file: ./SMTP/SMTP_Feature10_Reliable_Delivery_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _SMTP_step19: .. tab-set:: .. tab-item:: Reference links * Reference links