Linux 使用 curl 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14722556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using curl to send email
提问by NSNolan
How can I use the curl command line program to send an email from a gmail account?
如何使用 curl 命令行程序从 Gmail 帐户发送电子邮件?
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:
但是,file.txt 是电子邮件的内容,当我运行此命令时,出现以下错误:
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?
是否可以从仍然使用 curl 的个人服务器托管的帐户发送电子邮件?这是否使身份验证过程更容易?
采纳答案by bambam
curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from '[email protected]' --mail-rcpt '[email protected]' \
--upload-file mail.txt --user '[email protected]:password' --insecure
mail.txtfile contents:
mail.txt文件内容:
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:
附加信息:
I'm using
curl
version 7.21.6 with SSL support.The
--insecure
switch allowscurl
to perform "insecure" SSL connections and transfers. See this online resourcefor further details.It's considered a bad security practice to pass account credentials thru command line arguments. The above example is for demo purpose only.
You must turn on accessfor less secure apps.
回答by soloturn
if one wants to send mails as carbon copy or blind carbon copy:
如果您想以抄送或密送方式发送邮件:
curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from '[email protected]' --mail-rcpt '[email protected]' \
--mail-rcpt '[email protected]' --mail-rcpt '[email protected]' \
--upload-file mail.txt --user '[email protected]:password' --insecure
From: "User Name" <[email protected]>
To: "John Smith" <[email protected]>
Cc: "Mary Smith" <[email protected]>
Subject: This is a test
a BCC recipient eli is not specified in the data, just in the RCPT list.