Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. #Email support
  2. import smtplib
  3. from email.MIMEMultipart import MIMEMultipart
  4. from email.MIMEText import MIMEText
  5. from email.mime.image import MIMEImage
  6.  
  7. from subprocess import call
  8.  
  9. def sendEmail(result):
  10.     SENDTOTHIS = 'linus.neuman@dice.se'
  11.     print("Sending email to " + SENDTOTHIS)
  12.  
  13.     gmail_user = 'timetoworklazy@gmail.com'  
  14.     gmail_password = 'apansson123'
  15.  
  16.     sent_from = gmail_user  
  17.     to = SENDTOTHIS
  18.  
  19.     resultSubject = "Success!" if result.error == 0 else "Failure!"
  20.     msg = MIMEMultipart()
  21.     msg['From'] = "Fbcli Automation Notifier <%s>" % sent_from
  22.     msg['To'] = to
  23.     msg['Subject'] = "Sync/Build-Cycle Completed. " + resultSubject
  24.  
  25.     successString = "Automation completed successfully."
  26.     failString = "Automation resulted in error: " + result.reason
  27.  
  28.     resultMessage = successString if result.error == 0 else failString
  29.  
  30.     body = """
  31.     <body bgcolor="#000000">
  32.         <div style="color:white" align="center">
  33.             <b>{}</b>
  34.             <b> Get back to work!</b>
  35.         </div>
  36.     </body>
  37.     """.format(resultMessage)
  38.  
  39.     msgText = MIMEText(body, 'html')
  40.  
  41.     msg.attach(msgText)
  42.  
  43.     try:  
  44.         server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  45.         server.login(gmail_user, gmail_password)
  46.         server.sendmail(sent_from, to, msg.as_string())
  47.         server.quit()
  48.    
  49.         print('Email sent!')
  50.     except:
  51.         print('Something went wrong...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement