python 使用zmail收发电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用zmail收发电子邮件相关的知识,希望对你有一定的参考价值。
参考技术A 1、发送邮件:import zmail
server = zmail.server(' yourmail@example.com ’, 'yourpassword')
server.send_mail(' yourfriend@example.com ','subject':'Hello!','content_text':'By zmail.')
server.send_mail([' friend1@example.com ',' friend2@example.com '],'subject':'Hello!','content_text':'By zmail.')
2、接收最后一封邮件:
import zmail
server = zmail.server(' yourmail@example.com ’, '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(' yourmail@example.com ’, 'yourpassword')
server.send_mail(' yourfriend@example.com ', mail)
server.send_mail([' yourfriend@example.com ',' 12345@example.com '], 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(' yourfriend@example.com ',mail)
5、使用抄送:
server.send_mail([' foo@163.com ',' foo@126.com '],mail,cc=[' bar@163.com '])
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')
支持的列表:
以上是关于python 使用zmail收发电子邮件的主要内容,如果未能解决你的问题,请参考以下文章