python之邮件发送自动化

主题 Python

# -*- coding:utf-8 -*-
#@Time :     2020/3/24 22:55
#@Autor:     Mr.White
#@File :     发送邮件.py


一、导入所需要的类
1 import smtplib
2 import datetime
3 import time
4 from email.mime.text import MIMEText
5 from email.header import Header
二、服务配置
1 smtpserver='smtp.qq.com'
2 user='114558020@qq.com'
3 password='jiayou2021'
4 sender='114558020@qq.com'
5 #receive='114558020@qq.com'
6 receive='114558020@qq.com'
三、标题与内容
1 subject='python邮件自动化报表'
2 content='<html>今天是:{},宝宝出生的日子<h1 style="color:red">祝<br>宝宝生日快乐</h1><h1 style="color:orange">宝宝生日快乐</h1><h1 style="color:yellow">宝宝生日快乐</h1><h1 style="color:green">宝宝生日快乐</h1><h1 style="color:cyan">宝宝生日快乐</h1><h1 style="color:blue">宝宝生日快乐</h1><h1 style="color:purple">宝宝生日快乐</h1></html>'.format(datetime.datetime.now().strftime('%Y-%m-%d'))
四、组装
1 msg=MIMEText(content,'html','utf-8')
2 msg['Subject']=Header(subject,'utf-8')
3 msg['From']=sender
4 msg['To']=receive
五、设置发送与返回
1 smtp=smtplib.SMTP_SSL(smtpserver,465)
2 smtp.helo(smtpserver)
3 smtp.ehlo(smtpserver)
六、登陆、发件、日志
1 smtp.login(user,password)
2 print("start send email...")
3 smtp.sendmail(sender,receive,msg.as_string())
4 smtp.quit()
5 print("send eamil end!")

七、预览结果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值