msg['To']=receiver_email msg['Subject']='Excel文件'# 添加Excel文件作为附件withopen('data.xlsx','rb')asfile:attachment=MIMEApplication(file.read(),_subtype='xlsx')attachment.add_header('Content-Disposition','attachment',filename='data.xlsx')msg.attach(attachment)# 发送邮件withsmtplib.SMTP(smt...
msg_root = MIMEMultipart()msg_root.attach(MIMEText(content, 'html', 'utf-8'))msg_root['subject'] = subject msg_root['From'] = user msg_root['To'] = ','.join(receives)# msg_root['To'] = '3593882608@qq.com'# 构造附件3(附件为HTML格式的网页)att3 = MIMEText(open(send_mail,...
message.attach(MIMEText('这是菜鸟教程Python 邮件发送测试……','plain','utf-8')) # 构造附件1,传送当前目录下的 test.txt 文件 att1= MIMEText(open('1.xlsx','rb').read(),'base64','utf-8') att1["Content-Type"] ='application/octet-stream'# 这里的filename可以任意写,写什么名字,邮件中...
message.attach(MIMEText(email_text, 'plain', 'utf-8')) # 生成发件人名称(这个跟发送的邮件没有关系) message['From'] = Header(email_from, 'utf-8') # 生成收件人名称(这个跟接收的邮件也没有关系) message['To'] = Header(email_to, 'utf-8') # 生成邮件主题 message['Subject'] = Header...
可以使用email库来创建电子邮件对象,并使用MIMEMultipart、MIMEText和MIMEApplication类来构建邮件正文。以下是一个示例代码:# 创建电子邮件对象 msg = MIMEMultipart() # 添加邮件正文 body = MIMEText('这是包含Excel表的电子邮件正文。') msg.attach(body) # 添加HTML表格到正文中 html_part = MIMEText(html_...
('Content-Disposition','attachment',filename=annex_name)message.attach(part1)returnmessagedefsend_email(sender,password,receivers,mail_host,message):smtpObj=smtplib.SMTP()smtpObj.connect(mail_host,25)smtpObj.login(mail_user,password)smtpObj.sendmail(sender,receivers,message.as_string())print('...
MailWithFile.attach(AccessToTheAttachment)'''(发信服务器, 端口号)'''NowServer= smtplib.SMTP_SSL('smtp.qq.com', 465)#设置登录邮件的账号,授权码(可以自行去个人邮箱申请获取)NowServer.login('111111@qq.com','kiuxlnaoeexgjegj')#设置发送邮件:发件人、收件人NowServer.sendmail('111111111@qq.com'...
filename=file_path+"——"+i+".xlsx"#保存工作簿 dff.to_excel(filename,sheet_name=i,index=False)#i ndex=False忽略索引 print("工作簿拆分完成")#发送邮件 for j in split_list:my_email_from='XXXX'my_email_to='拆分Excel表格并发送邮件'my_email_subject=j+'2019年下半年销量数据表.xlsx'my_...
attachment.add_header('Content-Disposition', 'attachment', filename='04_月考勤表.xlsx') # 创建复合邮件对象 msg = MIMEMultipart() # 添加正文到复合邮件对象中 msg.attach(email_content) # 添加附件到复合邮件对象里 msg.attach(attachment) # 设置发送者信息 ...
"""# 第三方 SMTP 服务content=MIMEText('Yvon_早安阳光 简书博客')message=MIMEMultipart()# 多个MIME对象message.attach(content)# 添加内容message['From']=sender# 发件人message['To']=to_receiver# 收件人message['Subject']=Header('Yvon_早安阳光~简书博客','utf-8')# 主题# 添加Excel类型附件file_na...