test2.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import emails
  2. import smtplib
  3. from emails.template import JinjaTemplate
  4. # message = emails.Message(
  5. # subject=JinjaTemplate(subject_template),
  6. # html=JinjaTemplate(html_template),
  7. # mail_from=(settings.EMAILS_FROM_NAME, settings.EMAILS_FROM_EMAIL),
  8. # )
  9. message = f"test"
  10. subject = '註冊信'
  11. email_to ='oak@choozmo.com'
  12. # print('EEmail',email_to)
  13. message = emails.Message(
  14. subject=JinjaTemplate(message),
  15. html=JinjaTemplate(subject),
  16. mail_from=('zooey','zooey@choozmo.com'),
  17. )
  18. smtp_options = {"host": "smtp.gmail.com", "port": "587"}
  19. smtp_options["tls"] = True
  20. #smtp_options["ssl"] = True
  21. smtp_options["user"] = 'zooey@choozmo.com'
  22. smtp_options["password"] = 'bnufmjzkyezputip'
  23. environment={}
  24. print(email_to,environment,smtp_options)
  25. response = message.send(to=email_to, render=environment, smtp=smtp_options)
  26. print('RResponse',response)
  27. server = smtplib.SMTP()
  28. server.connect('smtp.gmail.com')
  29. server.login('zooey@choozmo.com','bnufmjzkyezputip')
  30. server.sendmail('zooey@choozmo.com', email_to,'hi 你好')
  31. server.quit()