使用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
使用档案.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 --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from 'username@gmail.com' --mail-rcpt 'john@example.com' \
--upload-file mail.txt --user 'username@gmail.com:password' --insecure
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!
其他信息:
-
我正在使用
curl
版本7.21.6并支援SSL。
I’m using
curl
version 7.21.6 with SSL support.
- insecure
开关允许 curl
执行不安全SSL连接
和传输。有关
的详细信息,请参见此在线资源此在线资源。
The --insecure
switch allows curl
to perform "insecure" SSL connections
and transfers. See this online resource this online resource for
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.
您必须打开安全性较低的应用的访问权限。
这篇关于使用curl发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!