使用curl发送电子邮件 [英] Using curl to send email

查看:237
本文介绍了使用curl发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用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

是否可以从由个人服务器托管的帐户发送电子邮件,还在使用卷曲?这样做会使身份验证过程更容易吗?

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!

附加信息:


  1. 我正在使用支持SSL的 curl 版本7.21.6。

- 不安全开关允许 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.

您必须开启访问权限安全的应用程序。

You must turn on access for less secure apps.

这篇关于使用curl发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆