在 Ubuntu 12.04 LTS 中使用 Gmail 配置 sSMTP

Viv*_*han 5 gmail smtp proxy

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

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=myusername@gmail.com

# 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
hostname=myusername@gmail.com
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
Run Code Online (Sandbox Code Playgroud)

我还在realiases文件中添加了别名,如下所示:

root:myusername@gmail.com:smtp.gmail.com:587
localusername:myusername@gmail.com:smtp.gmail.com:587
Run Code Online (Sandbox Code Playgroud)

我在一个代理服务器后面,当我设置自动代理配置 URL 并且我的系统代理设置是根据自动代理配置 URL 设置时,它可以工作。

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

sudo ssmtp someone@example.com
hello world 
Run Code Online (Sandbox Code Playgroud)

然后按 ctrl+d,我得到:

ssmtp: Cannot open smtp.gmail.com:587
Run Code Online (Sandbox Code Playgroud)

标题就是问题。

cot*_*eyr 3

mailhub=smtp.gmail.com:465

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

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

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

telnet smtp.gmail.com:465它应该有效,并返回乱码。


小智 1

我测试了上面的组合,端口是正确的。当然,587 是一个正确的端口,我为我的设置和工作选择了这个值。

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