MIME、邮件格式处理与HTML解析
1. MIME与邮件格式处理
MIME(多用途互联网邮件扩展)在邮件处理中扮演着重要角色。下面是一个将指定源目录下的所有文件打包成适合邮件发送的文件的示例代码:
def pack_mail(source_dir, **headers):
''' Given source_dir, a string that is a path to an existing, readable
directory, and arbitrary header name/value pairs passed in as named
arguments, packs all the files directly under source_dir (assumed to
be plain text files) into a mail message returned as a string.
'''
msg = email.Message.Message( )
for name, value in headers.iteritems( ):
msg[name] = value
msg['Content-type'] = 'multipart/mixed'
filenames = os.walk(source_dir).next( )[-1]
for filename in filenames:
m = email.Message.Message( )
m.add_header
超级会员免费看
订阅专栏 解锁全文
5370

被折叠的 条评论
为什么被折叠?



