zoukankan      html  css  js  c++  java
  • Python 发邮件例子

    Python 发邮件例子


    例子

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Date    : 2019-04-23 16:12:33
    # @Author  : BenLam
    # @Link    : https://www.cnblogs.com/BenLam/
    
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
    from email.mime.multipart import MIMEMultipart
    
    
    #发送邮箱服务器
    smtpserver='smtp.mxhichina.com'
    
    #发送邮箱用户/密码
    user='tester@qq.com'
    password='123456'
    
    #发送人
    sender='tester@qq.com'
    #收件人
    receiver='tester@qq.com'
    #主题
    subject='test E-mail'
    msgRoot=MIMEMultipart('test')
    
    #正文
    content='测试邮件地址!'
    cont=MIMEText(content,'plain','utf-8')
    
    #附件
    file=open('C:\bug.txt','rb').read()
    mark=MIMEText(file,'base64','utf-8')
    mark["Content-Type"]='application/octet-stream'
    mark["Content-Disposition"]='attachment;filename="bug.txt"'
    
    msgRoot['Subject'] = subject
    msgRoot.attach(cont)
    msgRoot.attach(mark)
    
    #开始发送邮件
    smtp=smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(user, password)
    smtp.sendmail(sender, receiver, msgRoot.as_string())
    smtp.quit()
    

    结果:

  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    期末总结
    第一次作业
    C语言I博客作业08
  • 原文地址:https://www.cnblogs.com/BenLam/p/10757403.html
Copyright © 2011-2022 走看看