Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

linux - 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 "<[email protected]>" --mail-rcpt "<[email protected]>" --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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
curl --ssl-reqd 
  --url 'smtps://smtp.gmail.com:465' 
  --user '[email protected]:password' 
  --mail-from '[email protected]' 
  --mail-rcpt '[email protected]' 
  --upload-file mail.txt

mail.txt file contents:

From: "User Name" <[email protected]>
To: "John Smith" <[email protected]>
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. You don't need to use the --insecure switch, which prevents curl from performing SSL connection verification. See this?online resource for further details.

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...