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 <some.sender@gmail.com>
To: Some Recipient <some.recipient@example.com>
Subject: Saying Hello
Date: Tue, 6 Jun 2023 04:15:06 -0100
Message-ID: <1234@local.machine.example>
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 'some.sender@gmail.com' \
--mail-rcpt 'some.recipient@example.com' \
--upload-file mail.txt \
--user 'some.sender@gmail.com: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
$