Chr*_*ris 9 python iphone mime
这是我的代码:
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"])
Run Code Online (Sandbox Code Playgroud)
虽然我可以在Gmail和Outlook上看到文本正文,但是在我的iPhone(6.1.3)上我只看到附件,而不是正文.
我在此评论中找到了我的解决方案:如何使用SMTP发送附件?
我的第一行应该是
msg = MIMEMultipart('mixed')
Run Code Online (Sandbox Code Playgroud)
而不是'替代'.
| 归档时间: |
|
| 查看次数: |
4313 次 |
| 最近记录: |