基于smtp发送,支持发送附件
if __name__ == '__main__': config = { 'from_addr' : 'XXX@gmail.com', 'password' : '******', 'to_addr' : 'xxx,yyy;zzz;aaa', #发送给xxx,yyy;抄送给zzz;密送给aaa 'smtp_server' : 'smtp.gmail.com', 'smtp_port' : 587 } subject = '来自python的测试邮件' text = "Dear all,\n\n\t这是一封来自python的测试邮件!\n" attachment_paths = [path1, path2] s = SendMail(*config) s.connect() s.MIMEMultipart(subject) s.add_text(text) s.add_attachment(attachment_paths) s.send()
评论