NSNolan NSNolan - 7 months ago 149
Linux Question

Using curl to send email

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?


This works for me

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

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.

Additional info

  1. I'm using curl version 7.21.6 with SSL support.
  2. The --insecure switch allows curl to perform "insecure" SSL connections and transfers. See this online resource for further details: http://curl.haxx.se/docs/sslcerts.html
  3. It's considered a bad security practice to pass account credentials thru command line arguments. The above example is for demo purpose only.