zoukankan      html  css  js  c++  java
  • python——三方电子邮件库pyzmail

    pyzmail比默认smtplib和mime模块简单很多。

    模块首页 http://pyzmail.readthedocs.io/en/latest/

    python3.2以上,pip install pyzmail

    python3.6,pip install pyzmail36

    python3.7,好像不兼容(20180725)import pyzmail

    import pyzmail
    #import smtplib
    
    #发件人
    sender = ('测试','xxx@xx.com')
    #收件人
    recipients = ['xx@xxxl.com']
    #邮件标题
    subject = '标题test'
    #邮件内容
    text_content = '内容中文文本'
    
    encoding = 'utf8'
    #用gbk编码可以解决foxmail乱码
    
    #构成邮件
    payload, mail_from, rcpt_to, msg_id = pyzmail.compose_mail(sender, recipients, subject, encoding, (text_content, encoding))
    
    #smtp用户密码
    smtp_host = 'smtp.xx.com'
    user = 'xxx@xx.com'
    passwd = 'xxxxx'
    
    '''
    #使用smtplib模块发邮件
    server = smtplib.SMTP(smtp_host)
    server.login(user, pwd)
    server.sendmail(mail_from, rcpt_to, payload)
    server.quit()
    '''
    
    #发送邮件
    ret=pyzmail.send_mail(payload,mail_from,rcpt_to,smtp_host,
                          smtp_login=user,smtp_password=passwd)
    
    if isinstance(ret, dict):
        if ret:
            print('failed recipients:', ', '.join(ret.keys()))
        else:
            print('success')
    else:
        print('error:', ret)
  • 相关阅读:
    使用greenDAO遇到的问题
    使用greenDAO生成DAO代码
    Spring中Bean的生命周期
    视频弹幕开源库
    最简MacOs10.8安装
    apache-virtual host
    带删除的EditText
    替换默认debug.keystore文件
    Intellij格式化java和xml
    【数据结构】之二叉树的java实现
  • 原文地址:https://www.cnblogs.com/maxgongzuo/p/9365157.html
Copyright © 2011-2022 走看看