栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

用python办公自动化发送邮件

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用python办公自动化发送邮件

用python发送邮件
import requests
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# 创建SMTP_SSL对象
smtp_obj = smtplib.SMTP_SSL(host='smtp.qq.com', port=465)

# 1. 授权登录
smtp_obj.login('账号@qq.com', '授权码')
m_part = MIMEMultipart()
# 发件人
m_part['From'] = '账号@qq.com'
# 收件人
m_part['To'] = '账号@qq.com'
m_part['Subject'] = '你的状态'

# 发送内容
content = """
     

你是头脑有病,污言秽语,殃及无辜祸害众生, 人模狗样,无可救药,无颜面对江东父老;

你在无中生有,无可救药,胡言乱语,

凭空捏造,无可救药,一路走好

""" # 附件 resp = requests.get('https://www.sohu.com/index.html') html_page = MIMEText(resp.text + content, 'html', 'utf-8') m_part.attach(html_page) # 添加pdf附件 with open('resources/用Python发送邮件和短信.pdf', 'rb') as file: pdf_file = MIMEText(file.read(), 'base64', 'utf-8') pdf_file['content-type'] = 'application/pdf' pdf_file['content-disposition'] = 'attachment; filename="用Python发送邮件和短信.pdf"' m_part.attach(pdf_file) # 添加xlsx附件 with open('resources/阿里巴巴2020年股票数据.xlsx', 'rb') as file: excel_file = MIMEText(file.read(), 'base64', 'utf-8') excel_file['content-type'] = 'application/vnd.ms-excel' excel_file['content-disposition'] = 'attachment; filename="alibaba-stock.xlsx"' m_part.attach(excel_file) # 2. 发送邮件 smtp_obj.sendmail( from_addr='发送账号@qq.com', to_addrs=['收件账号@qq.com'], msg=m_part.as_string() ) # 3. 结束会话 smtp_obj.quit()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/739127.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号