如何使用 curl 命令行程序从 gmail 帐户发送电子邮件?
我尝试了以下方法:
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 作为电子邮件的内容,但是,当我运行此命令时,我收到以下错误:
curl: (67) Access denied: 530
是否可以从个人服务器托管的帐户发送电子邮件,但仍使用 curl?这会使身份验证过程更容易吗?
最佳答案
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 连接验证。见 this online resource了解更多详情。通过帐户凭据传递被认为是一种不好的安全做法 命令行参数。使用
--netrc-file
。见 the documentation .您必须 turn on access对于不太安全的应用程序或更新的应用程序App passwords .
关于linux - 使用 curl 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14722556/