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

    有时候项目中会涉及发送电子邮件,因此,先记录一下

    import smtplib
    from email.mime.text import MIMEText
    #邮件接收者邮箱
    email='2201128470@qq.com'
    import easygui
    receiver=email
    subject='这是邮件主题'
    content='这是邮件内容'
    #邮件代理服务器,我使用的是163邮箱,其他邮箱也可以
    host='smtp.163.com'
    #邮件发送者的登录账号
    user_name='18258685895'
    #这里填邮箱授权码,不是账号的密码,如何获得邮箱授权码,请自行百度解决
    pwd='###'
    #邮件发送者邮箱账号
    sender='WXB_0101@163.com'
    
    message=MIMEText(content,'plain','utf-8')
    message['From']=sender
    message['to']=receiver
    message['Subject']=subject
    def sendMail():
        try:
            smtp_obj=smtplib.SMTP(host,25)
            smtp_obj.login(user_name,pwd)
            smtp_obj.sendmail(sender,receiver,message.as_string())
            easygui.msgbox('邮件发送成功')
        except smtplib.SMTPException as error:
            easygui.msgbox('邮件发送失败')
    def main():
        sendMail()
    if __name__ == '__main__':
        main()

  • 相关阅读:
    ListView点击事件
    ListView优化:
    自定义ListView
    ListView简单使用
    mysql中show processlist过滤和杀死线程
    自定义控件
    yum配置中driver-class-name: com.mysql.jdbc.Driver报错
    CSS+HTML
    maven的配置
    Model、ModelMap、ModelAndView的作用及区别
  • 原文地址:https://www.cnblogs.com/andrew3/p/13158227.html
Copyright © 2011-2022 走看看