sSMTP 故障排除:授权失败

Erw*_*ann 9 ssmtp

我的要求是:

  • 从终端发送电子邮件(为了批处理)
  • 将 pdf 文件附加到该电子邮件(除水印外,所有收件人的 pdf 文件均相同)
  • 指定回复地址 (myusername@gmail.com)

我尝试过“通过 gmail 发送单行消息的最简单答案是使用 ssmtp”,以及几种变体,并不断得到:

笔记本电脑 sSMTP[19226]:授权失败(535 5.7.8 https://support.google.com/mail/?p=BadCredentials d13sm3920147qkj.27 - gsmtp)

谷歌设置:

  • 已启用 IMAP
  • 允许安全性较低的应用程序已开启

对于我尝试的每个ssmtp.conf设置,我之前已经完成了DisplayUnlockCaptcha :

$echo "Testing...1...2...3" | ssmtp myusername@gmail.com
Run Code Online (Sandbox Code Playgroud)

仅查看所述线程/etc/ssmtp/ssmtp.conf,对于应如何设置尚未达成共识:

  • mailhub=smtp.gmail.com:587VS 465
  • UseTLS=YESUseSTARTTLS=Yes(或两者?)
  • hostname=localhost与默认放置在那里的任何内容(在我的例子中,laptop

有人可以提出解决这个问题的建议,并可能完整粘贴一个工作conf文件吗?

2017 年的一个帖子中有一个说法:

您无法使用普通密码使用外部应用程序,您必须访问https://security.google.com/settings/security/apppasswords

是这样吗?(我做不到)

还有哪些替代方案?

附:

  • 操作系统:Linux Mint 19 Tara
  • ssmtp 在升级/更新之前的全新安装中进行了测试
  • 几年前,我能够使用相同的操作系统(早期版本)发送电子邮件
  • 为了确保 AuthPass 的值正确,我用它手动登录我的谷歌帐户。

Erw*_*ann 9

使用以下 Google 设置:

IMAP enabled
Allow less secure apps is ON
Run Code Online (Sandbox Code Playgroud)

解决方案是设置应用程序密码在此输入图像描述

注意: Google 设置的应用程序密码要求首先为您尝试为其配置 ssmtp 的帐户启用双因素身份验证。

/var/ssmtp/ssmtp.conf:

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

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
# Modified 06/27/2020:
# mailhub=mail
root=mysusername@gmail.com
AuthUser=mysusername@gmail.com
#AuthPass=[usual gmail pwd] # aint' gonna work
AuthPass=[pwd generated by https://myaccount.google.com/apppasswords]
#UseTLS=YES
#mailhub=smtp.gmail.com:465
UseSTARTTLS=Yes
mailhub=smtp.gmail.com:587

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

# The full hostname
hostname=laptop

# 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)

在终端上:

$echo "Testing...1...2...3" | ssmtp recipient@gmail.com
Run Code Online (Sandbox Code Playgroud)

我的gmailbox收到了: 在此输入图像描述

附:

  1. 我不认为在没有解释的情况下否决投票有什么用处。
  2. 对于问题(附件)中所述的第二个要求,mutt就像一个魅力一样

更新于 12/01/2022

使用msmtp并且因为不太安全的应用程序被禁用

  1. 开启两步验证
  2. 使用 Name='msmtp'生成应用程序密码
  3. 执行$ touch ~/.msmtprc,并使用 2) 修改其内容如下,
    # content of /home/user/.msmtprc
    # do: `$ chmod 600 /home/user/.msmtprc`
    # gmail
    account google-name@gmail.com
    host smtp.gmail.com
    port 587
    tls on
    tls_starttls on
    auth on
    user google-name
    from google-name@gmail.com
    # https://myaccount.google.com/apppasswords
    password xxxxxxxxxxxxxxxx
    # default account
    account default : google-name@gmail.com
Run Code Online (Sandbox Code Playgroud)
  1. $ chmod 600 /home/user/.msmtp
  2. $ echo "Testing...1...2...3" | msmtp recipient.address@domain

这会发送至密件抄送,请在此处查找替代方案。