【发布时间】:2021-09-02 04:25:28
【问题描述】:
我编写了一个代码来发送 Outlook 邮件,该邮件的正文应包含 CSV 文件的内容,邮件部分工作正常。但表格似乎变形了。
[![邮件正文][1]][1]
所以无论如何这里都有安排。让它变得漂亮。
这是我的代码:
def sendMailt():
print("*** SENDING MAIL ****")
email_user = 'ABC@domain.com'
email_send = 'DCF@domain.com'
subject = ''
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = 'Hi Team , Please Open This attachment for Folderstat Report,'
msg.attach(MIMEText(body, 'plain'))
text = """
Hello, Friend.
Here is your data:
{table}
Regards,
Me"""
with open(filtered_CSV) as input_file:
reader = csv.reader(input_file)
data = list(reader)
text = text.format(table=tabulate(data, headers=['Unnamed: 0','id','path','name','extension','size','FolderSize in GB','LastAccessTime','LastModifiedTime','LastCreationTime','folder','Total Number of files','Absolute File Count','depth','parent','uid','Oldest File Timestamp','Recent File Timestamp','Folder Modified Timestamp','Status','md5]'] ,tablefmt='orgtbl'))
server = smtplib.SMTP('domain')
sender = 'ABC@domain.com'
reciever = ['DCF@domain.com']
server.sendmail(sender, reciever, text)
server.quit()
print("Mail SEND")
当我收到邮件时,也看不到主题或收件人 ID [1]:https://i.stack.imgur.com/y5Gxy.png
【问题讨论】: