email - Ansible 邮件模块发送邮件失败
问题描述
我可以使用以下命令从我的 Linux 主机发送电子邮件:
echo 'These are contents of my mail' | mailx -s 'This is my email subject' -a last2day_access_log catherine@gmail.com
telnet 到 localhost 25 也在同一 Linux 主机上成功连接。
在同一个 linux 主机上尝试了 ansible 邮件模块,如下所示:
- hosts:
localhost
tasks:
- mail:
host: localhost
port: 25
to: 'catherine@gmail.com'
subject: 'Ansible-report'
body: 'System {{ ansible_hostname }} has been successfully provisioned.'
delegate_to: localhost
但是,我收到以下错误:
TASK [mail] ******************************************************************************************
task path: /web/playbooks/test.yml:17
Using module file /usr/lib/python2.7/site-packages/ansible/modules/notification/mail.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: localuser
<localhost> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_zSM8eA/ansible_module_mail.py", line 372, in main
smtp.sendmail(sender_addr, set(addr_list), composed)
File "/usr/lib64/python2.7/smtplib.py", line 735, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (553, '5.5.4 <root>... Domain name required for sender address root', 'root')
fatal: [localhost -> localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"attach": null,
"bcc": null,
"body": "System mylocalhost has been successfully provisioned.",
"cc": null,
"charset": "us-ascii",
"headers": null,
"host": "localhost",
"password": null,
"port": 25,
"secure": "try",
"sender": "root",
"subject": "Ansible-report",
"subtype": "plain",
"timeout": 20,
"to": "catherine@gmail.com",
"username": null
}
},
"msg": "Failed to send mail to catherine@gmail.com: (553, '5.5.4 <root>... Domain name required for sender address root', 'root')",
"rc": 1
}
to retry, use: --limit @/web/playbooks/test.retry
PLAY RECAP *******************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
以下是我在 Linux 主机上的主机名:
cat /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
mylocalhost
$ uname -a
Linux mylocalhost 3.10.0-1160.11.1.el7.x86_64 #1 SMP Mon Nov 30 13:05:31 EST 2020 x86_64 x86_64 x86_64 GNU/Linux
你能建议吗?
解决方案
根据错误消息告诉您的内容:
SMTPSenderRefused: (553, '5.5.4 <root>... Domain name required for sender address root', 'root')
看起来您的邮件任务实际上是在尝试将邮件发送为<root>
,如果您只在本地发送邮件,这可以工作,但很可能会在外界被拒绝。
解决方法是更改您的任务并from
在您的电子邮件中添加一个正确的:
- mail:
host: localhost
port: 25
from: 'someone@example.org'
to: 'catherine@gmail.com'
subject: 'Ansible-report'
body: 'System {{ ansible_hostname }} has been successfully provisioned.'
delegate_to: localhost
推荐阅读
- amazon-web-services - AWS SES:用户无权对资源执行 ses:SendEmail
- docker - 如何在相当普通的笔记本电脑上提高 WSL/docker 容器的性能?
- android - 无法在 Flutter 应用程序中隐藏进度对话框
- python - 使用 Python 和请求的自签名 CA 验证错误
- c++ - C++ const_iterator 到 forward_list 的迭代器
- sql - PostgreSQL 删除行,其中等于以逗号分隔的字符串
- r - R中三列之间的匹配大小写
- github - Jupyter 笔记本在 github 中不再像往常一样格式化
- ios13 - CKAccountChanged 通知只收到一次
- node.js - 将 MERN 应用程序部署到 Vercel 或 heroku 时出现问题?