• 发送邮件


    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
  • 相关阅读:
    root----TH1
    linux debug
    python基础 文件操作
    linux下挂载硬盘
    安装双系统
    路由器相关
    007-python 获取网卡实时流量(转)
    ssh密钥登录失败(转)
    当while read line 遇到 ssh(转)
    python实用功能之001-邮件发送
  • 原文地址:https://www.cnblogs.com/kite123/p/13785505.html
Copyright © 2020-2023  润新知