Fails to send emails with Office 365
Actually, there is one bug and one improvement in this ticket.
System info: Ubuntu 14.04 64 bit with current elastalert code from git.
Using Office365 to send emails fails with the following exception:
ERROR:root:Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/elastalert.py", line 825, in alert
return self.send_alert(matches, rule, alert_time=None)
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/elastalert.py", line 898, in send_alert
alert.alert(matches)
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/alerts.py", line 241, in alert
self.smtp.sendmail(self.from_addr, to_addr, email_msg.as_string())
File "/usr/lib/python2.7/smtplib.py", line 742, in sendmail
raise SMTPRecipientsRefused(senderrs)
SMTPRecipientsRefused: {'[email protected]': (553, '5.5.4 <[email protected]>... Domain name required for sender address ElastAlert')}
ERROR:root:Uncaught exception running rule Test Alert 2: {'[email protected]': (553, '5.5.4 <[email protected]>... Domain name required for sender address ElastAlert')}
It would be great if it was displaying an error message instead of a stacktrace.
I've experience a similar error when creating scripts using sendmail. Scripts that worked fine with GMail failed when using Office365 (we are using postfix to relay to Office365). The reason is that GMail didn't require one and was automatically setting the 'From' field based on the credentials you used.
Office365 is different. Even if you're logging in with credentials, you MUST set the 'From' field or it will fail miserably.
So, it would be great if we could set the 'from' field in the rules or globally in the configuration file (or both).
The 'from' issue is fixed but I get a different exception:
ERROR:root:Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/elastalert.py", line 825, in alert
return self.send_alert(matches, rule, alert_time=None)
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/elastalert.py", line 898, in send_alert
alert.alert(matches)
File "/usr/local/lib/python2.7/dist-packages/elastalert-0.0.55-py2.7.egg/elastalert/alerts.py", line 241, in alert
self.smtp.sendmail(self.from_addr, to_addr, email_msg.as_string())
File "/usr/lib/python2.7/smtplib.py", line 745, in sendmail
self.rset()
File "/usr/lib/python2.7/smtplib.py", line 469, in rset
return self.docmd("rset")
File "/usr/lib/python2.7/smtplib.py", line 394, in docmd
return self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 365, in getreply
+ str(e))
SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer
Hm, that's unfortunately not a very helpful exception. I'm not sure what the problem is. I've only confirmed that this works with postfix and Gmail. You could try toggling smtp_ssl, or using another port if Office365 offers it, though I doubt you would have even hit the first issue if that was the problem.
It was due to a misconfiguration. Sendmail was started and it stopped our postfix which was handling the mail.
Thanks.
Are the smtp parameters documented somewhere outside of the code?
http://elastalert.readthedocs.org/en/latest/ruletypes.html#email
@ThomasdOtreppe @Qmando
Can someone share me the email alert setting for office 365 ?
I'm using the below for gmail .
alert:
- "email" smtp_host: smtp.gmail.com smtp_port: 465 smtp_ssl : true from_addr: "[email protected]" smtp_auth_file: /usr/share/elasticsearch/smtp_auth_file.yml
email: