在 Ubuntu 12.04 LTS 中为 Gmail 配置 sSMTP

在 Ubuntu 12.04 LTS 中为 Gmail 配置 sSMTP

我正在尝试获得一个适用于 Ubuntu 的良好命令行电子邮件工具,以便我可以通过终端或简单的 bash 脚本发送简单的电子邮件,甚至附加文件。我的ssmtp配置文件文件现在看起来像这样:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
[email protected]

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
rewriteDomain=gmail.com

# The full hostname
[email protected]
AuthUser=myusername
AuthPass=mypassword
UseSTARTTLS=YES 
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

我还在重新命名文件如下:

root:[email protected]:smtp.gmail.com:587
localusername:[email protected]:smtp.gmail.com:587

我使用代理服务器,当我设置自动代理配置 URL 时,代理服务器就会工作,并且我的系统代理设置会根据自动代理配置 URL 进行设置。

但是,当我使用以下命令从终端运行 sSMTP 时:

sudo ssmtp [email protected]
hello world 

然后按 ctrl+d,我得到:

ssmtp: Cannot open smtp.gmail.com:587

标题就是问题。

答案1

mailhub=smtp.gmail.com:465

端口错误。您的别名也需要更新。

Gmail 仅允许来自远程主机的 SSL 电子邮件,其他连接通常不起作用。启用 SSL 并使用端口 465。

如果这不起作用,请验证与 telnet 的连接:

telnet smtp.gmail.com:465它应该可以工作并返回乱码。

答案2

我已经测试了上面的组合,端口是正确的。毫无疑问,587 是正确的端口,我为我的设置和工作选择了这个值。

此处的问题可能是由于防火墙中存在传出规则,或 gmail 的安全策略有新的限制。您必须前往https://myaccount.google.com并检查“访问不太安全的应用程序”:必须允许,默认情况下是不允许的。

相关内容