zoukankan      html  css  js  c++  java
  • 发送邮件

    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.mime.application import MIMEApplication
    from com.myconf import conf #获取配置文件中的信息
    
    
    def send_email(file_path,file_name):
    
        # 第一步连接到smtp服务器
        smtp=smtplib.SMTP_SSL("smtp.qq.com",465)
        smtp.login(conf.get('email','sender'),conf.get('email','sender_pwd'))
    
        # 第二步构建邮件
        smg=MIMEMultipart()
    
        text_smg = MIMEText(open(file_path, 'r', encoding='utf8').read(), "html") # 邮件类型:html格式,plain是文本
        smg.attach(text_smg)
    
        file_msg = MIMEApplication(open(file_path, "rb").read())
        file_msg.add_header('content-disposition', 'attachment', filename=file_name)
        smg.attach(file_msg)
    
        smg["Subject"] = conf.get('email','subject')
        smg["From"] = conf.get('email','sender')
        smg["To"] = conf.get('email','receiver')
    
    
        # 第三步发送邮件
        smtp.send_message(smg,from_addr=conf.get('email','sender'),to_addrs=conf.get('email','receiver'))
    
    
    
    if __name__ == '__main__':
        pass
  • 相关阅读:
    socket 常用api
    socket客户端小例
    select和ioctl的一个简单测试
    git 相关配置
    pvr转png
    flash 中matrix
    moto x使用注意事项
    互联网思维将颠覆我们的认知
    微信公众账号怎么快速增加粉丝
    Discuz如何解除某个会员的QQ绑定状态
  • 原文地址:https://www.cnblogs.com/kite123/p/13785505.html
Copyright © 2011-2022 走看看