Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Email support
- import smtplib
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEText import MIMEText
- from email.mime.image import MIMEImage
- from subprocess import call
- def sendEmail(result):
- SENDTOTHIS = 'linus.neuman@dice.se'
- print("Sending email to " + SENDTOTHIS)
- gmail_user = 'timetoworklazy@gmail.com'
- gmail_password = 'apansson123'
- sent_from = gmail_user
- to = SENDTOTHIS
- resultSubject = "Success!" if result.error == 0 else "Failure!"
- msg = MIMEMultipart()
- msg['From'] = "Fbcli Automation Notifier <%s>" % sent_from
- msg['To'] = to
- msg['Subject'] = "Sync/Build-Cycle Completed. " + resultSubject
- successString = "Automation completed successfully."
- failString = "Automation resulted in error: " + result.reason
- resultMessage = successString if result.error == 0 else failString
- body = """
- <body bgcolor="#000000">
- <div style="color:white" align="center">
- <b>{}</b>
- <b> Get back to work!</b>
- </div>
- </body>
- """.format(resultMessage)
- msgText = MIMEText(body, 'html')
- msg.attach(msgText)
- try:
- server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
- server.login(gmail_user, gmail_password)
- server.sendmail(sent_from, to, msg.as_string())
- server.quit()
- print('Email sent!')
- except:
- print('Something went wrong...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement