草庐IT

MIMEText

全部标签

Python 3 smtplib 发送带有 unicode 字符

我在Python3中使用smtplib通过电子邮件发送unicode字符时遇到问题。这在3.1.1中失败,但在2.5.4中有效:importsmtplibfromemail.mime.textimportMIMETextsender=to='ABC@DEF.com'server='smtp.DEF.com'msg=MIMEText('€10')msg['Subject']='Hello'msg['From']=sendermsg['To']=tos=smtplib.SMTP(server)s.sendmail(sender,[to],msg.as_string())s.quit()我尝

python - 将 MIMEText 编码为引用的打印品

Python支持相当实用的MIME-Library名为email.mime。我想要实现的是获得一个包含纯UTF-8文本的MIME部分,以将其编码为引用的打印品而不是base64。尽管库中提供了所有功能,但我没有设法使用它:例子:importemail.mime.text,email.encodersm=email.mime.text.MIMEText(u'Thisisthetextcontainingünicöde',_charset='utf-8')m.as_string()#=>Leadstoabase64-encodedmessage,asbase64isthedefault.e

python - 用于在 Python 中发送带有文件附件的电子邮件的 MIMEMultipart、MIMEText、MIMEBase 和有效负载

在没有太多MIME知识的情况下,我尝试学习如何编写Python脚本来发送带有文件附件的电子邮件。在交叉引用Python文档、StackOverflow问题和一般网络搜索后,我确定了以下代码[1]并测试了它是否有效。importsmtplibfromemail.MIMEMultipartimportMIMEMultipartfromemail.MIMETextimportMIMETextfromemail.MIMEBaseimportMIMEBasefromemailimportencodersfromaddr="YOUREMAIL"toaddr="EMAILADDRESSYOUSEND

python - 发送电子邮件时 MIMEText UTF-8 编码问题

这是我发送电子邮件的代码的一部分:servidor=smtplib.SMTP()servidor.connect(HOST,PORT)servidor.login(user,usenha)assunto=str(self.lineEdit.text())para=str(globe_email)texto=self.textEdit.toPlainText()textos=str(texto)corpo=MIMEText(textos.encode('utf-8'),_charset='utf-8')corpo['From']=usercorpo['To']=paracorpo['Su