利用python发送邮件

##作业
##每日早上8点半启动任务
##读取网易新闻。csv,随机抽一行新闻内容
##将新闻内容发送至自己的邮箱

import yagmail
import schedule
import time
from openpyxl import load_workbook
import csv,random

def read_news():
    lines=[]
    with open('2019年10月网易新闻.csv','r') as file:
        news=csv.reader(file)
##        print(type(news))   #<class '_csv.reader'>
        for row in news:
            lines.append(row)
    i=random.randint(1,len(lines)-1)
    return lines[i]

    
def send_mail():
    [news_body, news_source, news_thread, news_time, news_title, news_url, source_url]=read_news()
    yag=yagmail.SMTP(user='#我的腾讯企业邮箱#',host='smtp.exmail.qq.com')
    contents=[
        news_title,
        news_thread,
        news_body,
        news_time,
        news_source,
        news_url
        ]
    yag.send('#我的腾讯企业邮箱#','请查收今日新闻',contents)

schedule.every().day.at("08:00").do(send_mail)
while True:
    schedule.run_pending()
    time.sleep(1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值