Sending Email from the Command Line with cURL
June 06, 2023 —
Gregg Szumowski
Let’s assume that you had a RFC 5822 formatted file named
mail.txt as follows:
From: Some Sender <[email protected]>
To: Some Recipient <[email protected]>
Subject: Saying Hello
Date: Tue, 6 Jun 2023 04:15:06 -0100
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".
You can forward this to a email recipient using Google’s SMTP with
the following curl command provided you have a Google app
password:
$ curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from '[email protected]' \
--mail-rcpt '[email protected]' \
--upload-file mail.txt \
--user '[email protected]:your-gmail-app-password'
Output should be something like this:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12 0 0 100 12 0 10 0:00:01 0:00:01 --:--:-- 10
$