Etherarp
Etherarp

Networking, Security, Linux

Share


Sending Emails with cURL

In this tutorial, we will look at how the cURL utility can be used to send out emails. This is useful for things like automated alerts

Rohan MolloyRohan Molloy

Curl is a command line utility found on most modern Linux distributions used to retrieve content from  the internet. However, it can do a lot more than that and supports a plethora of protocols, including TFTP, SFTP, and SMTP.

Sending an Email

[rohan@desktop ~]$ echo "Subject: Sending an Email with Curl!

Just wanted to check you were able to receive this email, sent over the curl command.
Has it gone into spam?.

Thanks.
" | curl -s --ssl smtp://$SERVER --mail-from $FROM --mail-rcpt $TO --upload-file /dev/stdin --user rohan@example.etherarp.net
Enter host password for user 'rohan@example.etherarp.net':
[rohan@desktop ~]$

Let's see if the email was delivered (nb: the address has been changed to prevent spam)

Email sent with Curl

Securing the credentials

In this example, the --user field did not specify a password, this results in a prompt. If you don't want to enter it manually, you can either hardcode it somewhere (bad) or use GPG encryption. With GPG, the gpg-agent can be configured to store credentials in memory. This way, you only need to enter the password once. Configuring gpg is out of the scope of this article

[rohan@desktop ~]$ curl -s --ssl smtp://$SERVER --mail-from $FROM --mail-rcpt $TO --upload-file $EMAIL --user rohan@example.etherarp.net:$(pass email/rohan@example.etherarp.net 2>/dev/null)
[rohan@desktop ~]$
Author

Rohan Molloy

View Comments