Using curl to send email

2019-01-07 05:03发布

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?

1条回答
冷血范
2楼-- · 2019-01-07 05:13
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.
Bye!

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 this online resource for further details.

  3. It’s considered a bad security practice to pass account credentials thru command line arguments. The above example is for demo purpose only.

  4. You must turn on access for less secure apps.

查看更多
登录 后发表回答