我正在尝试从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]:失败了! => {“已更改”:false,“失败”: 是的,“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(代码,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
答案 0 :(得分:0)
您面临的问题是使用正确的用户名和密码导致的身份验证问题。用于从Gmail帐户发送电子邮件但未指定应用专用密码的密码。
您需要:
a)设置&#3; 2步验证&#39;对于发件人Gmail帐户。
b)然后,您需要在Google帐户设置中create an app specific password。
使用新生成的应用专用密码,您就可以像下面的示例一样发送邮件
- 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