使用 curl 发送电子邮件 [英] Using curl to send email
问题描述
如何使用 curl 命令行程序从 Gmail 帐户发送电子邮件?
How can I use the curl command line program to send an email from a gmail account?
我尝试了以下方法:
curl -n --ssl-reqd --mail-from "<sender@gmail.com>" --mail-rcpt "<receiver@server.tld>" --url smtps://smtp.gmail.com:465 -T file.txt
使用 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
是否可以从仍然使用 curl 的个人服务器托管的帐户发送电子邮件?这是否会使身份验证过程更容易?
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 --ssl-reqd
--url 'smtps://smtp.gmail.com:465'
--user 'username@gmail.com:password'
--mail-from 'username@gmail.com'
--mail-rcpt 'john@example.com'
--upload-file mail.txt
mail.txt 文件内容:
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!
附加信息:
我使用的是支持 SSL 的
curl
7.21.6 版.
您不需要使用 --insecure
开关,它可以防止 curl
执行 SSL 连接验证.请参阅此在线资源了解更多详情.
You don't need to use the --insecure
switch, which prevents curl
from performing SSL connection verification. See this online resource for further details.
传递帐户凭据被认为是一种糟糕的安全做法命令行参数.使用 --netrc-file
.请参阅文档.
It’s considered a bad security practice to pass account credentials thru
command line arguments. Use --netrc-file
. See the documentation.
您必须为安全性较低的应用或较新的开启访问权限="//myaccount.google.com/apppasswords" rel="noreferrer">应用密码.
You must turn on access for less secure apps or the newer App passwords.
这篇关于使用 curl 发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!