lihongya111
2021-06-26 15:01
采纳率: 100%
浏览 18

python将程序运行结果发送到对应邮件

小白求教大神:

我想把对excel的操作输出直接发送给我的邮箱。网上找了段发送邮件代码可以成功发送邮件。但是想请教下这些命令的输出(包含3个df类型数据以及3个饼图),发送这样的数据我应该怎么修改发送的内容这一行message = MIMEText(comment_df, "plain", "utf-8")

 

import smtplib
from email.mime.text import MIMEText
from email.header import Header
import pandas as pd

comment_df = pd.read_excel(r"C:\Users\lih21\Desktop\python\task 3.1\comment_nm.xlsx")
comment_df

mail_host = "smtp.qq.com"
mail_user = "326263013@qq.com"
auth = "fyxdixumqvbqbhjh"  # 这个是自己qq邮箱的授权码
sender = "32626301@qq.com"
receivers = ["XXX@dell.com"]

message = MIMEText(comment_df, "plain", "utf-8")
message['from'] = Header("32626301@qq.com", "utf-8")
message['to'] = Header("XXX@dell.com", "utf-8")
subject = "this is the subject"
message['subject'] = Header(subject, "utf-8")
try:
    smtpObj = smtplib.SMTP_SSL('smtp.qq.com')  # 建立smtp连接,qq邮箱必须用ssl边接,因此边接465端口
    smtpObj.connect(host = "smtp.qq.com", port = 465)
    smtpObj.login(mail_user, auth)  # 登陆
    smtpObj.sendmail(sender, receivers, message.as_string())  # 发送
    print("succeed sending")
    smtpObj.quit()
except smtplib.SMTPException as err:
    print("can not send the email")
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 江天暮雪丨 2021-06-26 15:35
    已采纳

    你这个发个邮件附件会不会好一点?
    另外,别把自己邮箱和授权码放出来啊,注意隐私

    点赞 1 打赏 评论
  • API工程师404 2021-06-26 18:16

    顶楼上,先写个静态页把数据和图加进去,完了直接发送就OK了

    点赞 1 打赏 评论

相关推荐 更多相似问题