mail可调用smtp转发邮件,但是本地邮件无法发送?

安装

sudo apt install msmtp  msmtp-mda

设置

vim .msmtprc
account default
host smtp.qq.com
from x1@qq.com
auth on
tls on
tls_certcheck off
user x1@qq.com
password xxxx
logfile ~/.msmtp.log

mail命令调用smtp.qq.发送邮件:

echo "Testing msmtp " | mail -s "hi root" -r x1@qq.com -- aa@yahoo.com

成功了!但是发现无法发送本地邮件了

echo "cron task work done " | mail -s "hi root" root

user用户发送邮件给root.

报错:
mail: cannot send message: Process exited with a non-zero status

查看日志:

Aug 24 20:47:31 host=smtp.qq.com tls=on auth=on user=x1@qq.com from=debian@debian.debian recipients=root@debian.debian smtpstatus=501 smtpmsg='501 Mail from address must be same as authorization user.' errormsg='envelope from address debian@debian.debian not accepted by the server' exitcode=EX_DATAERR

这样也不行

echo "cron task work done " | mail -s "hi root" -r debian@debian.debian  root

日志

Aug 29 06:56:39 host=smtp.qq.com tls=on auth=on user=x1@qq.com from=debian@debian.debian recipients=root@debian.debian smtpstatus=501 smtpmsg='501 Mail from address must be same as authorization user.' errormsg='envelope from address debian@debian.debian not accepted by the server' exitcode=EX_DATAERR

如何解决?

阅读 3.4k
1 个回答

根据你提供的信息,msmtp 的配置中遇到了一个常见的问题,即邮件发送时出现 "Mail from address must be same as authorization user" 的错误。这是因为 SMTP 服务器要求发送邮件的 "From" 地址必须与授权用户相同,以防止滥用。

要解决这个问题,请按照以下步骤进行操作:

  1. 编辑 .msmtprc 配置文件:

    vim ~/.msmtprc

    确保以下几点:

    • from 选项的值必须与 user 选项的值相同。
    • from 选项的值必须使用授权用户的完整邮箱地址,例如 x1@qq.com

    你的 .msmtprc 文件应该像这样:

    account default
    host smtp.qq.com
    from x1@qq.com
    auth on
    tls on
    tls_certcheck off
    user x1@qq.com
    password xxxx
    logfile ~/.msmtp.log
  2. 更新 mail 命令中的 -r 选项:

    echo "cron task work done " | mail -s "hi root" -a "From: x1@qq.com" root

    通过添加 -a "From: x1@qq.com",将发送邮件的 "From" 地址设置为授权用户的邮箱地址。

这样应该就可以成功发送邮件了。如果问题仍然存在,请确保你使用的是有效的授权用户、正确的邮箱地址和密码,并且与你的 SMTP 服务器设置兼容。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏