简体   繁体   English

Python电子邮件不是一个整体

[英]Python Email is not coming as a single body

Code for sending email via python-3: 通过python-3发送电子邮件的代码:
(here, df1 is dataframe, s is smtp server object) (这里,df1是数据帧,s是smtp服务器对象)

part1 = MIMEText(df1.to_html(index=False,col_space=1000),'html',"utf-8")
part2 = MIMEText(message, 'plain',"utf-8")

msg.attach(part1)
msg.attach(part2)

s.sendmail(MY_ADDRESS,email, msg.as_string())

This is not coming as single body. 这不是一个整体。
part1 is coming as body for email and part2 is coming as attachment. part1作为电子邮件的正文出现,part2作为附件出现。
I need to have it as single body for email. 我需要将其作为电子邮件的整体。

msg_text = df1.to_html(index=False,col_space=1000)
msg_text = message + msg_text

part1 = MIMEText(msg_text , 'html',"utf-8")
msg.attach(part1)

s.sendmail(MY_ADDRESS,email, msg.as_string())

MIMEText should be used only once. MIMEText应该只使用一次。
Do all the attachment in the string previously. 以前在字符串中完成所有附件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM