def mail_episode(ep):
# ok did cheat here, got this from cverna
# https://github.com/pybites/challenges/blob/community/17/cverna/podcast.py
# TODO: test on server
smtp_server = smtplib.SMTP('smtp.gmail.com', 587)
smtp_account = os.environ.get('MAIL_ACCOUNT') or sys.exit('Need mail user')
smtp_password = os.environ.get('MAIL_PASSWORD') or sys.exit('Need mail pw')
mailto = os.environ.get('MAILTO') or sys.exit('Need mail to')
smtp_server.ehlo()
smtp_server.starttls()
try:
smtp_server.login(smtp_account, smtp_password)
except smtplib.SMTPAuthenticationError:
print('Could not login to the smtp server please check your username and password')
sys.exit(1)
msg = MIMEText('\nHi this week podcast is {} you can download it from here {}'.
format(ep.title, ep.link))
msg['Subject'] = 'My podcast of the week'
msg['From'] = smtp_account
msg['To'] = mailto
smtp_server.send_message(msg)
smtp_server.quit()
评论列表
文章目录