Using curl to send email

command-line, curl, email, gmail, linux

Solution

curl --ssl-reqd \
  --url 'smtps://smtp.gmail.com:465' \
  --user 'username@gmail.com:password' \
  --mail-from 'username@gmail.com' \
  --mail-rcpt 'john@example.com' \
  --upload-file mail.txt

mail.txt file contents:

From: "User Name" <username@gmail.com>
To: "John Smith" <john@example.com>
Subject: This is a test

Hi John,
I’m sending this mail with curl thru my gmail account.
Bye!

Additional info:

I’m using `curl` version 7.21.6 with SSL support.

You don't need to use the `--insecure` switch, which prevents `curl` from performing SSL connection verification. See this online resource for further details.

It’s considered a bad security practice to pass account credentials thru command line arguments. Use `--netrc-file`. See the documentation.

You must turn on access for less secure apps or the newer App passwords.

Problem

How can I use the curl command line program to send an email from a gmail account? I have tried the following: ``` curl -n --ssl-reqd --mail-from "<sender@gmail.com>" --mail-rcpt "<receiver@server.tld>" --url smtps://smtp.gmail.com:465 -T file.txt ``` With file.txt being the email's contents, however, when I run this command I get the following error: ``` curl: (67) Access denied: 530 ``` Is it possible to send an email from an account that is hosted by a personal server, still using curl? Does that make the authentication process easier?

Original source

Related problems