我正尝试通过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}
答案 0 :(得分:4)
您缺少from
参数...
在这里看看:Ansible Mail Module
它说参数---
- 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
默认为root。由于未设置,因此邮件服务器说它无效。可能gmail与Office365的处理方式不同。
尝试一下...
@Service
public class EmployeeServiceImpl implements EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
@Override
public Employee getEmployeeByName(String name) {
return employeeRepository.findByName(name);
}
}