Guest User

Untitled

a guest
Aug 8th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import sys
  2. from email.mime.text import MIMEText
  3. from smtplib import SMTP_SSL, SMTPException
  4. import logging
  5.  
  6.  
  7. def admin_email(recipients, subject, content):
  8.  
  9. smtp_server = ''
  10. sender = ''
  11. username = sender
  12. password = ''
  13. text_subtype = 'html'
  14.  
  15. try:
  16. msg = MIMEText(content, text_subtype)
  17. msg['Subject'] = subject
  18. msg['From'] = sender
  19. for i in recipients:
  20. if not i:
  21. recipients.remove(i)
  22. if recipients != [None]:
  23. msg['To'] = ', '.join(recipients)
  24. else:
  25. recipients = []
  26.  
  27. conn = SMTP_SSL(smtp_server)
  28. conn.set_debuglevel(False)
  29. conn.login(username, password)
  30. try:
  31. conn.sendmail(sender, recipients + [''], msg.as_string())
  32. finally:
  33. conn.close()
  34.  
  35. except SMTPException:
  36. e = sys.exc_info()[0]
  37. # Log (e)
  38. logging.error(e)
Add Comment
Please, Sign In to add comment