Sending mails via curl

24 Mar 2019

You can easily send emails from your mail account via curl. You only need to know your mail service provider SMTP address (and data that you use to authenticate like username and password).

First, you need to create a file containing mail headers. I will name it mail.txt.

Date: "Sun, 24 Mar 2019 20:35:22 +0100"
From: "Artur Motyka" <[email protected]>
To: "Artur Motyka" <[email protected]>
Subject: Meowdy

Hi Artur,
How are you?

TIP: You can get your current date using date +"%a, %d %b %Y %H:%M:%S %z" (it will return something like Sun, 24 Mar 2019 20:47:55 +0100)

Now we need to log in into our mail account and send it.

curl 'smtp://' --mail-from '[email protected]' --mail-rcpt '[email protected]' --user '[email protected]:HappyDoggo`' --upload-file mail.txt

That will send an mail from artur[at] (--mail-from parameter) account to arturmotyka99[at] (--mail-rcpt parameter) using artur[at] account with HappyDoggo password (--user parameter).

It just works