8
Đây là mã của tôi:Python smtplib.sendmail Mime Multipart cơ thể không hiển thị trên iPhone
FROM = ''
TO = ''
SMTPSERVER = ''
MYEMAILPASSWORD = ""
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def physicallySend(listOfAttachments):
msg = MIMEMultipart('alternative')
msg['Subject'] = "Testing"
msg['From'] = FROM
msg['To'] = TO
textPart = MIMEText("Hello. I should be able to see this body.", 'plain')
msg.attach(textPart)
for attachmentFilename in listOfAttachments:
fp = open(attachmentFilename, 'rb')
file1 = MIMEBase('application','csv')
file1.set_payload(fp.read())
fp.close()
encoders.encode_base64(file1)
file1.add_header('Content-Disposition','attachment;filename=%s' % attachmentFilename)
msg.attach(file1)
server = smtplib.SMTP(SMTPSERVER)
server.ehlo()
server.starttls()
server.login(FROM, MYEMAILPASSWORD)
server.sendmail(FROM, to, msg.as_string())
server.quit()
return True
physicallySend(["testfile.csv"])
Trong khi tôi có thể thấy mức phạt thân văn bản trên Gmail và Outlook, tuy nhiên trên iPhone của tôi (6.1.3) Tôi chỉ thấy chấp trước, chứ không phải thân thể.
Tôi gặp vấn đề tương tự, ngoại trừ việc tôi đính kèm hình ảnh trái ngược với tệp csv. Tôi đã nhận thấy rằng nếu tôi chỉ đơn giản là không bao gồm hình ảnh/thêm tiêu đề cho nó, cơ thể hiển thị tốt. Hãy cho tôi biết nếu bạn có thể khắc phục vấn đề này. Cảm ơn! –