+ when bot fail then send mail

This commit is contained in:
urinx
2017-05-25 16:21:48 +08:00
parent 97f347b8f8
commit 123993c3cc
9 changed files with 70 additions and 14 deletions
@@ -0,0 +1,20 @@
#!/usr/bin/env python
# coding: utf-8
#===================================================
import sendgrid
from sendgrid.helpers.mail import *
#===================================================
class SGMail(object):
def __init__(self, apikey, from_email, to_email):
self.sg = sendgrid.SendGridAPIClient(apikey=apikey)
self.from_email = Email(from_email)
self.to_email = Email(to_email)
def send_mail(self, subject, plain_content, type='text/plain'):
content = Content(type, plain_content)
mail = Mail(self.from_email, subject, self.to_email, content)
response = self.sg.client.mail.send.post(request_body=mail.get())
return response.status_code == 202