簡體   English   中英

Ansible smtp 郵件發送

[英]Ansible smtp mail send

我正在嘗試從 Ansible 發送郵件。

- hosts: all
  tasks:
  - mail:
      host: smtp.gmail.com

      port: 587

      username: ****@gmail.com

      password: *******

      to: John Smith ***@gmail.com

      subject: 'Ansible-report'

      body: 'System  has been successfully provisioned.'

    delegate_to: localhost

但我收到一個錯誤

致命:[host1 -> localhost]:失敗! => {"changed": false, "failed": true, "msg": "身份驗證到 smtp.gmail.com:587 失敗,請檢查您的用戶名和/或密碼", "rc": 1}

我使用官方網站http://docs.ansible.com/ansible/latest/mail_module.html 中的示例

據我了解,源新模塊 ANSIBLE 中已經存在 SMTP 身份驗證。 文件“/tmp/ansible_K94pcN/ansible_module_mail.py”,第 304 行,在主 smtp.login(用戶名,密碼)中

文件“/usr/lib64/python2.7/smtplib.py”,第 621 行,在登錄時引發 SMTPAuthenticationError(code, resp)

致命:[host1 -> localhost]:失敗! => {“改變”:假,

"failed": true,

"invocation": {

    "module_args": {

        "attach": null,
        "bcc": null,
        "body": "System ubuntu has been successfully provisioned.",
        "cc": null,
        "charset": "us-ascii",
        "headers": null,
        "host": "smtp.gmail.com",
        "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
        "port": 587,
        "secure": "starttls",
        "sender": "root",
        "subject": "Ansible-report",
        "subtype": "plain",
        "timeout": 20,
        "to": "Cristiano Ross <cristianooross@gmail.com>",
        "username": "victorradin9@gmail.com"
    }
},
"msg": "Authentication to smtp.gmail.com:587 failed, please check your usern              ame and/or password",
"rc": 1

您面臨的問題是使用正確的用戶名和密碼從 Gmail 帳戶發送電子郵件而未分配應用特定密碼而導致的身份驗證問題。

你需要:

a) 為發件人 gmail 帳戶設置“兩步驗證”。

b) 然后您需要在您的谷歌帳戶設置中創建一個應用程序專用密碼

使用新生成的應用程序特定密碼,您將能夠像下面的示例一樣發送郵件

   - mail:
     host: smtp.gmail.com
     port: 587
     secure: starttls
     charset: utf-8
     sender: victorradin9@gmail.com
     username: victorradin9@gmail.com
     password: your app password generated by google for you goes here
     to: 'cristianooross@gmail.com'
     subject: Ya u rite

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM