• Check this channel: https://www.youtube.com/@mailserverguru
  • IMAP (Internet Message Access Protocol) synchronizes emails across devices, while POP3 (Post Office Protocol version 3) downloads emails to a single device
    • For IMAP, Emails are stored on the mail server and synchronized with the client. Changes made on one device reflect on others. It’s Suitable for accessing emails across multiple devices; full sync support
    • For POP3, Emails are downloaded to the client device and typically deleted from the server (unless configured otherwise). Best for single-device use; no syncing
    • IMAP and POP3 are for receiving emails, while SMTP is for sending emails
  • Mail servers handles sending, receiving, and storing emails using components like the Mail Transfer Agent (MTA) for routing, the Mail User Agent (MUA) for user access, and the Mail Delivery Agent (MDA) for local message delivery
    • Receiving and storing emails are optional

    • Components:

      • MTA (Mail Transfer Agent): transfers or relays email between servers and routes it toward the recipient doing server-to-server over port 25. Examples: Postfix, Sendmail, Exim
      • MUA (Mail User Agent): the client application a user uses to compose, send, receive and manage their email. Examples: Microsoft Outlook, Mozilla Thunderbird, Apple Mail, Gmail
      • MSA (Mail Submission Agent): accepts outgoing mail from a user’s MUA, applies submission-checks, and forwards it to an MTA. Many MTAs act as MSAs; any outgoing-mail submission server on port 587 may serve as an MSA
      • LDA (Local Delivery Agent): delivers email from the mail server into the local user’s mailbox on the same server
      • MDA (Mail Delivery Agent): takes an email from the mail server and delivers it into the recipient’s mailbox
      • MRA (Mail Retrieval Agent): pulls or retrieves email from a remote mail server so a mail client can access it (IMAP and POP3)
      • SMTP (Simple Mail Transfer Protocol): the protocol used to transmit email between mail servers (and from client to server for submission) over the network
    • Say you have a Postfix mail server and you want to send an email using the command below

      echo "This is a test email body" | mail -s "Test Subject" [email protected]
      
      • The “client” process that issues the mail command is a Mail User Agent (MUA)
      • Postfix plays the role of a Mail Transfer Agent (MTA) (and internally also a Message Submission Agent, MSA)
      • On the destination side there is another MTA for the recipient’s domain, and finally a Mail Delivery Agent (MDA) that delivers into the recipient’s mailbox
    • Flow example (reference):

      1. Kate composes a reply in the Mail User Agent and presses «Send»
      2. Kate's Mail User Agent sends the email to Mail Submission Agent, which is located on Kate's mail server
      3. Mail Submission Agent trasnfers the email to Mail Transfer Agent
      4. Kate's Mail Transfer Agent makes a request to the DNS server and recieves an address of John's mail server
      5. Kate's Mail Transfer Agent sends the email to John's Mail Transfer Agent (possibly, via relays)
      6. John's Mail Transfer Agent transfers the email to Mail Delivery Agent
      7. Mail Delivery Agent saves the email in the John's mailbox on disk
      8. John's Mail User Agent asks to Mail Retrieval Agent whether new emails are appeared and receives the email from Kate
      9. John reads Kate's email
      Step Role interaction Typical ports
      MUA → MSA/MTA (submission) Mail User Agent → Mail Submission Agent or Mail Transfer Agent 587 (submission) or 465 (SMTPS)
      MTA → MTA (relay) Mail Transfer Agent → Mail Transfer Agent 25 (SMTP)
      MTA → MDA (local delivery) Mail Transfer Agent → Mail Delivery Agent If local same-host: none
      MUA → MDA (retrieval) Mail User Agent → Mail Delivery Agent (IMAP/POP3 server) 143/993 (IMAP), 110/995 (POP3)
  • SMTP (Simple Mail Transfer Protocol) is an application used by mail servers to send, and relay outgoing email between senders and receivers
    • SMTP can also stand for Sending Mail To People
    • SMTP provider: a company that provides email delivery services using the SMTP protocol. SMTP providers operate email servers and provide APIs or SMTP credentials to allow users to send email messages through their servers. Examples of SMTP providers include SendGrid, Amazon SES, and Mailgun
    • SMTP relay: a type of email delivery service that allows you to send email messages through a third-party email server instead of using your own email server. SMTP relays can be used to improve email deliverability and reduce the risk of emails being flagged as spam. SMTP relays can be provided by SMTP providers, ISPs, or other organizations
    • Email subaddressing: also known as plus sign (+) trick, is popularized by Gmail and now supported by most email providers. It allows creating a new email address by simply appending the plus sign(+) to your current email address ([email protected])
      • The subaddressing acts as a label and can be useful for managing email, site registrations, and filters
      • Its better to use email aliases to protect your privacy because subaddressing can have privacy risks
      • Subaddressing works automatically with your existing email account
      • Beneficial for QA when doing test workflows to create multiple "unique" emails for testing account creation, login, or email-related workflows
  • Traditional ports:
    • Port 25: This is the traditional SMTP port used for server-to-server SMTP relay (MTA→MTA)
      • Outbound port 25 blocked is usually blocked (even in some cloud providers like Azure)
    • Port 587: Reserved for message submission by a mail user agent (MUA) or message submission agent (MSA) to the mail server (MTA) with authentication and typically STARTTLS
    • Port 465: Historically used for SMTPS (SMTP over implicit TLS where ) for submission. Now considered legacy, but still supported by some systems
  • DMARC, DKIM, and SPF are three email authentication methods. Together, they help prevent spammers, phishers, and other unauthorized parties from sending emails on behalf of a domain* they do not own. Without them, your mail server’s messages are much more likely to be marked as spam or blocked by recipient systems
    • DKIM and SPF can be compared to a business license or a doctor's medical degree displayed on the wall of an office, they help demonstrate legitimacy. DMARC tells mail servers what to do when DKIM or SPF fail, whether that is marking the failing emails as "spam," delivering the emails anyway, or dropping the emails altogether

    • SPF, DKIM, and DMARC records are stored in the Domain Name System (DNS), which is publicly available. All stored as DNS TXT records

    • SPF (Sender Policy Framework): Specifies which servers can send emails for your domain. The recipient checks your DNS SPF record to verify the sender’s IP. Helps prevent spoofing but can break when emails are forwarded

      Reference

      Reference

    • DKIM (DomainKeys Identified Mail): Adds a cryptographic signature to verify that an email hasn’t been altered and was sent from an authorized domain. Uses a private key to sign and a public key (in DNS) for verification

      Reference

      Reference

    • DMARC (Domain-based Message Authentication, Reporting & Conformance): Builds on SPF and DKIM to define how to handle emails that fail authentication. It enforces alignment between visible “From” domains and sending domains and provides reports for visibility

      Reference

      Reference

    • Recommended video: https://youtu.be/c9fLp5uIxp8?si=oW177lYN_l-apV_-