2014-01-16 38 views
1

所以,這是我的代碼有,把它從python.org,但是當我發送電子郵件contaning特殊字符,如「E」或「NAO」,它顯示了這樣的「à© 「或」não「在outlook.com上,但其他電子郵件工作正常。的Python econding郵件MimeMultipart的

有沒有什麼辦法可以解決這個問題?我嘗試設置.py編碼,html meta enconding但沒有工作。

copia = str(copia) 
    msg = MIMEMultipart('alternative') 
    msg['Subject'] = assunto 
    msg['From'] = de 
    msg['To'] = para 
    msg['Cc'] = copia   
    # Create the body of the message (a plain-text and an HTML version). 
    text = email_texto 
    html = email_html 

    # Record the MIME types of both parts - text/plain and text/html. 
    part1 = MIMEText(text, 'plain') 
    part2 = MIMEText(html, 'html') 

    # Attach parts into message container. 
    # According to RFC 2046, the last part of a multipart message, in this case 
    # the HTML message, is best and preferred. 
    msg.attach(part1) 
    msg.attach(part2) 


    server = smtplib.SMTP('smtp.gmail.com:587') 
    server.ehlo() 
    server.starttls() 
    server.ehlo() 
    server.login(de, self.senha) 
    server.sendmail(de, (para, copia), msg.as_string()) 
    server.quit() 

回答

相關問題