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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:56:26  来源:igfitidea点击:

Using curl to send email

linuxemailcurlcommand-linegmail

提问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:

附加信息:

  1. I'm using curlversion 7.21.6 with SSL support.

  2. The --insecureswitch allows curlto perform "insecure" SSL connections and transfers. See this online resourcefor 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 accessfor less secure apps.

  1. 我使用的是curl支持 SSL 的 7.21.6 版。

  2. --insecure开关允许curl执行“不安全”的 SSL 连接和传输。有关更多详细信息,请参阅此在线资源

  3. 通过命令行参数传递帐户凭据被认为是一种糟糕的安全做法。以上示例仅用于演示目的。

  4. 您必须为不太安全的应用程序打开访问权限

回答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.