email - Ansible 邮件模块不适用于 Office 365

标签 email smtp ansible

我正在尝试从 ansible 发送电子邮件

如果我用 gmail 尝试它,它工作得很好,但是,如果我用 office 365 尝试它不工作。

下面是我的剧本。

---
  - name: Mail Sendig using Ansible
    hosts: localhost
    tasks:
      - name: Mail sending using Mail Module
        mail:
          host: "smtp.office365.com"
          port: 587
          username: "dcalert@mycompany.com"
          password: "mypasswd"
          to: "Jon Snow <jon.snow@mycompany.com>"
          subject: "Ansible"
          body: "Hello from Ansible"
          secure: starttls

我遇到了错误

ASK [Send email]
*******************************************************************
An exception occurred during task execution. To see the full 
traceback, use -vvv. The error was: SMTPSenderRefused: (501, '5.1.7 
Invalid address', 'root')
fatal: [localhost -> localhost]: FAILED! => {"changed": false, 
"failed": true, "msg": "Failed to send mail to 
jon.snow@mycompany.com: (501, '5.1.7 Invalid address', 
'root')", "rc": 1}

最佳答案

您缺少 from 参数...

看这里:Ansible Mail Module

它表示参数 from 默认为 root。由于您没有设置它,邮件服务器说它无效。可能 gmail 的处理方式与 office365 不同。

试一试...

---
  - name: Mail Sendig using Ansible
    hosts: localhost
    tasks:
      - name: Mail sending using Mail Module
        mail:
          host: "smtp.office365.com"
          port: 587
          username: "dcalert@mycompany.com"
          password: "mypasswd"
          from: "dcalert@mycompany.com"
          to: "Jon Snow <jon.snow@mycompany.com>"
          subject: "Ansible"
          body: "Hello from Ansible"
          secure: starttls

关于email - Ansible 邮件模块不适用于 Office 365,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52401148/

相关文章:

javascript - 该 Node 库如何能够从任何(可能拥有的)域向我发送电子邮件?

email - 如何仅为 Outlook 2013 将动画图像插入电子邮件正文?

python - 将用户输入传递给节日

php - 带有 SSL 套接字的 CodeIgniter 和 Gmail SMTP 超时

smtp - 使用 SMTP 的最大电子邮件附件大小?

amazon-web-services - 'ansible_date_time' 未定义

c# - 如何将 html 页面存储在 xml 文件中?

ruby - 使用 SMTP 和 Gmail 的通知电子邮件在 Redmine 上不起作用

ansible - 本地运行模块

variables - 我可以在 ansible 中将公共(public)变量放在 playbook 之外的地方