mailer.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import smtplib
  2. import traceback
  3. import os
  4. from email.mime.text import MIMEText
  5. from email.mime.image import MIMEImage
  6. from email.mime.multipart import MIMEMultipart
  7. from email.message import EmailMessage
  8. import codecs
  9. gmail_user = 'ming@choozmo.com'
  10. gmail_password='lzpxinencaawsjus'
  11. sent_from = gmail_user
  12. #to = ['jared@choozmo.com','nina.huang@choozmo.com','ana@choozmo.com','ming@choozmo.com','mike@choozmo.com','andy@choozmo.com','hana@choozmo.com','stacy@choozmo.com','wen@choozmo.com','yukyo@choozmo.com','fxp87257@gmail.com','noodlesloves@gmail.com']
  13. def send_left_not_enough(msg_in,email):
  14. to = [email]
  15. msg = MIMEMultipart()
  16. msg['Subject'] = 'AI Spokesgirl 服務餘額不足 '
  17. msgAlternative = MIMEMultipart('alternative')
  18. msg.attach(msgAlternative)
  19. text = MIMEText(msg_in,'html','utf-8')
  20. msgAlternative.attach(text)
  21. try:
  22. server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  23. server.ehlo()
  24. server.login(gmail_user, gmail_password)
  25. server.sendmail(sent_from, to, msg.as_string())
  26. server.close()
  27. print ('Email sent!')
  28. except:
  29. traceback.print_exc()
  30. print ('Something went wrong...')
  31. def register_verify(msg_in,email):
  32. to = [email]
  33. msg = MIMEMultipart()
  34. msg['Subject'] = '驗證您的信箱'
  35. msgAlternative = MIMEMultipart('alternative')
  36. msg.attach(msgAlternative)
  37. text = MIMEText(msg_in,'html','utf-8')
  38. msgAlternative.attach(text)
  39. try:
  40. server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  41. server.ehlo()
  42. server.login(gmail_user, gmail_password)
  43. server.sendmail(sent_from, to, msg.as_string())
  44. server.close()
  45. except:
  46. traceback.print_exc()