Backbrain   Archive

Curl send email

Sending email with curl is done with the SMTP protocol.

From: John Smith <john@example.com>
To: Joe Smith <smith@example.com>
Subject: an example.com example email
Date: Mon, 7 Nov 2016 08:45:16

Dear Joe,
Welcome to this example email. What a lovely day.
curl smtp://mail.example.com --mail-from myself@example.com --mail-rcpt \
receiver@example.com --upload-file email.txt

Secure mail transfer

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

--ssl           Try SSL/TLS (FTP, IMAP, POP3, SMTP)
--ssl-reqd      Require SSL/TLS (FTP, IMAP, POP3, SMTP)

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

curl --ssl-reqd smtp://mail.example.com:587 --mail-from myself@example.com \
     --mail-rcpt receiver@example.com --upload-file email.txt \
     --user 'user@your-account.com:your-account-password'