Guest User

Untitled

a guest
Nov 20th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. try:
  2. startT = time.time()
  3. with SMTP(cfg['smtp_host'], port=cfg['smtp_port']) as smtp:
  4. smtp.set_debuglevel(2) # Uncomment this if you wish to see the SMTP conversation / STARTLS neg.
  5. smtp.ehlo(name='sparkpostSMIME')
  6. if 'starttls' in smtp.esmtp_features:
  7. smtp.starttls() # raises an exception if it fails. If continues, we're good
  8. smtp.ehlo(name='sparkpostSMIME')
  9. mode_str = 'STARTTLS'
  10. else:
  11. mode_str = 'plain'
  12. if cfg['smtp_user'] and cfg['smtp_password']:
  13. smtp.login(cfg['smtp_user'], cfg['smtp_password'])
  14. print('Opened SMTP connection ({}) to {}, port {}, user="{}", password="{}"'.format(
  15. mode_str,
  16. cfg['smtp_host'],
  17. cfg['smtp_port'],
  18. cfg['smtp_user'],
  19. '*' * len(cfg['smtp_password'])))
  20. print('Sending {}\tFrom: {}\tTo: {} '.format(args.emlfile, msgOut.get('From'), msgOut.get('To')))
  21. smtp.send_message(msgOut)
  22. endT = time.time()
  23. print('OK - in', round(endT - startT, 3), 'seconds')
  24. except SMTPException as e:
  25. print(e)
  26. exit(1)
Add Comment
Please, Sign In to add comment