podcast.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:100DaysOfCode 作者: pybites 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号