你试试看
msg['To'] = ', '.joint(self.username, '[email protected]') #逗号后面有个空格
1、发送邮件:import zmail
server = zmail.server(' [email protected] ’, 'yourpassword')
server.send_mail(' [email protected] ',{'subject':'Hello!','content_text':'By zmail.'})
server.send_mail([' [email protected] ',' [email protected] '],{'subject':'Hello!','content_text':'By zmail.'})
2、接收最后一封邮件:
import zmail
server = zmail.server(' [email protected] ’, 'yourpassword')
latest_mail = server.get_latest()
zmail.show(latest_mail)
3、发送带附件的邮件:
import zmail
mail = {
'subject': 'Success!', # Anything you want.
'content_text': 'This message from zmail!', # Anything you want.
'attachments': ['/Users/zyh/Documents/example.zip','/root/1.jpg'], # Absolute path will be better.
}
server = zmail.server(' [email protected] ’, 'yourpassword')
server.send_mail(' [email protected] ', mail)
server.send_mail([' [email protected] ',' [email protected] '], mail)
4、发送html格式邮件:
with open('/Users/example.html','r') as f:
content_html = f.read()
mail = {
'subject': 'Success!', # Anything you want.
'content_html': content_html,
'attachments': '/Users/zyh/Documents/example.zip', # Absolute path will be better.
}
server.send_mail(' [email protected] ',mail)
5、使用抄送:
server.send_mail([' [email protected] ',' [email protected] '],mail,cc=[' [email protected] '])
6、自定义server
server = zmail.server('username','password',smtp_host='smtp.163.com',smtp_port=994,smtp_ssl=True,pop_host='pop.163.com',pop_port=995,pop_tls=True)
7、根据ID取回邮件:mail = server.get_mail(2)
根据日期、主题、发送人取回邮件:
mail = server.get_mails(subject='GitHub',after='2018-1-1',sender='github')
mail = server.get_mails(subject='GitHub',start_time='2018-1-1',sender='github',start_index=1,end_index=10)
8、查看邮箱统计
mailbox_info = server.stat() #结果为包含两个整型的元组: (邮件的数量, 邮箱的大小).
9、删除邮件:MailServer.delete(which)
10、保存附件:zmail.save_attachment(mail,target_path=None,overwrite=False)
11、保存邮件:zmail.save(mail,name=None,target_path=None,overwrite=False)
12、读取邮件:zmail.read(file_path,SEP=b'\r\n')
支持的列表: