2014-04-30 9 views
8

Ecco il mio codice:Python smtplib.sendmail corpo Mime Multipart non mostrato su 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"]) 

Mentre posso vedere il corpo del testo benissimo su Gmail e Outlook, ma sul mio iPhone (6.1.3) Vedo solo l'allegato e non il corpo.

+0

Ho lo stesso identico problema, ad eccezione del fatto che allego un'immagine anziché i file CSV. Ho notato che se semplicemente non includo l'immagine/aggiungi intestazioni per esso, il corpo si mostra bene. Fammi sapere se sei in grado di risolvere questo problema. Grazie! –

risposta

Problemi correlati