Compare commits
1 Commits
4cca0e8aa9
...
e7fe463b82
Author | SHA1 | Date |
---|---|---|
kuldeep.k@cisinlabs.com | e7fe463b82 |
29
main.py
29
main.py
|
@ -64,21 +64,16 @@ class SMTPWebhookApp:
|
||||||
client.starttls()
|
client.starttls()
|
||||||
client.ehlo()
|
client.ehlo()
|
||||||
client.login(msg["From"], FROM_MAIL_PASSWORD)
|
client.login(msg["From"], FROM_MAIL_PASSWORD)
|
||||||
except Exception as e:
|
|
||||||
time.sleep(0.2)
|
|
||||||
logging.error("To: {}, error: {}".format(msg['To'], e))
|
|
||||||
return {"status": 500, "message": "some error in from mail "
|
|
||||||
"login: {}".format(e)}
|
|
||||||
|
|
||||||
try:
|
|
||||||
client.sendmail(msg['From'], msg['To'], msg.as_string())
|
client.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||||
client.quit()
|
response = {"status": 200, "message": "mail sent successfully"}
|
||||||
logging.info("To: {}, mail sent successfully".format(TO_MAIL))
|
logging.info("To: {}, mail sent successfully".format(TO_MAIL))
|
||||||
return {"status": 200, "message": "mail sent successfully"}
|
except smtplib.SMTPException as e:
|
||||||
except Exception as e:
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
logging.error("To: {}, error: {}".format(TO_MAIL, e))
|
logging.error("To: {}, error: {}".format(TO_MAIL, e))
|
||||||
return {"status": 500, "message": "some error: {}".format(e)}
|
response = {"status": 500, "message": "some error: {}".format(e)}
|
||||||
|
finally:
|
||||||
|
client.quit()
|
||||||
|
return response
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def send_mail(self):
|
def send_mail(self):
|
||||||
|
@ -99,14 +94,10 @@ CHERRYPY_SERVER_PORT = 8081
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
# SMTP_SERVER_HOST = os.environ["SMTP_SERVER_HOST"]
|
SMTP_SERVER_HOST = os.environ["SMTP_SERVER_HOST"]
|
||||||
# TO_MAIL = os.environ["TO_MAIL"]
|
TO_MAIL = os.environ["TO_MAIL"]
|
||||||
# FROM_MAIL = os.environ["FROM_MAIL"]
|
FROM_MAIL = os.environ["FROM_MAIL"]
|
||||||
# FROM_MAIL_PASSWORD = os.environ["FROM_MAIL_PASSWORD"]
|
FROM_MAIL_PASSWORD = os.environ["FROM_MAIL_PASSWORD"]
|
||||||
SMTP_SERVER_HOST = "smtp.gmail.com"
|
|
||||||
TO_MAIL = "test111@mailinator.com"
|
|
||||||
FROM_MAIL = "cis.dev393@gmail.com"
|
|
||||||
FROM_MAIL_PASSWORD = "akeel@123#"
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyError("Please check missing environment variables: "
|
raise KeyError("Please check missing environment variables: "
|
||||||
"SMTP_SERVER_HOST, TO_MAIL, FROM_MAIL, "
|
"SMTP_SERVER_HOST, TO_MAIL, FROM_MAIL, "
|
||||||
|
|
Loading…
Reference in New Issue