#自定义处理邮件收发地址的显示内容
def _format_addr(s):
name,addr = parseaddr(s)
print name
print addr
#将邮件的name转换成utf-8格式,addr如果是unicode,则转换utf-8输出,否则直接输出addr
return formataddr((\
Header(name,'utf-8').encode(),\
def _format_addr(s):
name,addr = parseaddr(s)
print name
print addr
#将邮件的name转换成utf-8格式,addr如果是unicode,则转换utf-8输出,否则直接输出addr
return formataddr((\
Header(name,'utf-8').encode(),\
addr.encode("utf-8") if isinstance(addr,unicode) else addr))
#邮件对象
msg['From'] = _format_addr(u'测试机 <%s>'%from_addr)
msg['to'] = _format_addr(u'吴鹏rhythm <%s>'%to_addr)
下图是使用上面代码后,收发件人的邮箱地址显示
以下是python自动发送邮件的完整代码:
#coding=utf-8
from email.header impor