SMTP

    curl supports sending data to a an SMTP server, which combined with the right
    set of command line options makes an email get sent to a set of receivers of
    your choice.

    When sending SMTP with curl, there are a two necessary command line options
    that must be used.

    • You need to tell the server which email address that is the sender of the
      email with --mail-from. It is important to realize that this email
      address is not necessarily the same as is shown in the From: line of the
      email text.

    Then, you need to provide the actual email data. This is a (text) file
    formatted according to RFC
    5322
    . It is a set of headers and a
    body. Both the headers and the body need to be correctly encoded. The headers
    typically include To:, From:, Subject:, Date: etc.

    1. From: John Smith <john@example.com>
    2. Subject: an example.com example email
    3. Dear Joe,
    4. Welcome to this example email. What a lovely day.

    Some mail providers allow or require using SSL for SMTP. They may use a
    dedicated port for SSL or allow SSL upgrading over a plaintext connection.

    If your mail provider has a dedicated SSL port you can use smtps:// instead of
    smtp://, which uses the SMTP SSL port of 465 by default and requires the entire
    connection to be SSL. For example smtps://smtp.gmail.com/.

    However, if your provider allows upgrading from plaintext to secure transfers
    you can use one of these options:

    You can tell curl to try but not require upgrading to secure transfers by
    adding --ssl to the command:

    1. curl --ssl smtp://mail.example.com --mail-from myself@example.com

    You can tell curl to require upgrading to using secure transfers by adding
    --ssl-reqd to the command:

    To connect to the mail server at mail.example.com and send your local
    computer’s host name in the HELO / EHLO command:

    1. curl smtp://mail.example.com

    You can of course as always use the -v option to get to see the
    client-server communication.

    To instead have curl send client.example.com in the HELO / EHLO command
    to the mail server at , use:

    When you send email with an ordinary mail client, it will first check for an
    MX record for the particular domain you want to send email to. If you send an
    email to , the client will get the MX records for example.com
    to learn which mail server(s) to use when sending email to example.com users.

    curl does no MX lookups by itself. If you want to figure out which server to
    send an email to for a particular domain, we recommend you figure that out
    first and then call curl to use those servers. Useful command line tools to
    get MX records with include ‘dig’ and ‘nslookup’.