我正在尝试发送带有两个csv文件附件的电子邮件。我的问题是,当我打开附件时,没有读取换行符('\ n'),并且邮件中的文本全部放在一行上。如何获取附件以读取换行符?
我尝试使用不同的换行符。
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = config.email_address
msg['To'] = ", ".join(config.email_recipients)
msg['Subject'] = subject
msg.attach(MIMEText(text))
#get all the attachments
for file in filenames:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(file, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-disposition', 'attachment', filename='"%s"' % file)
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(config.email_address, config.email_password)
mailServer.sendmail(config.email_address, to, msg.as_string())
mailServer.close()
When reading the attachment, I see "word word word word word" instead of
"word
word
word
word"