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()

  • 相关阅读:
    Windows下的免安装版MySQL配置
    spket插件安装并设置JQuery自动提示
    js生成条形码——JsBarcode
    金明的预算方案
    文化之旅
    方格取数
    天使的起誓
    最大差值
    A%B Problem
    取数游戏
  • 原文地址:https://www.cnblogs.com/andrew3/p/13158227.html
Copyright © 2011-2022 走看看