Navigation

    Gpushare.com

    • Register
    • Login
    • Search
    • Popular
    • Categories
    • Recent
    • Tags

    python代码训练完成后邮件通知功能

    技术分享📚有奖励
    2
    3
    155
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 1
      158****8051 last edited by

      功能:邮件通知功能
      说明:需要开通邮箱的stmp服务,使用时需要修改发件邮箱、收件邮箱、stmp服务授权密码
      说明:
      运行成功后python输出窗口打印“success”

      import smtplib
      from email.mime.text import MIMEText
      from email.mime.multipart import MIMEMultipart
      import time
      
      
      def send_email():
          time_info = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime())
      
          message = MIMEMultipart()
          sender = 'xxxxxxx@126.com' # 参数1:发送者邮箱
          receiver = 'xxxxxxx@qq.com' # 参数2:接受者邮箱
          message['From'] = sender
          message['To'] = receiver
          password = 'xxxxxxxx' # 参数3:stmp服务授权密码
      
          # 邮件的内容
      
          content = "{0} 已完成:{0}".format(time_info)
          textApart = MIMEText(content)
          message.attach(textApart)  # 邮件的文字部分
          message['Subject'] = time_info  # 邮件的标题
      
          try:
              server = smtplib.SMTP('smtp.126.com') # 发件邮箱的SMTP服务器地址
              server.login(sender, password)
              server.sendmail(sender, receiver, message.as_string())
              print('success')
              server.quit()
          except smtplib.SMTPException as e:
              print('error:', e)  # 打印错误
      

      关于如何开启邮箱的SMTP服务
      d8c40427-c9d3-4fd3-aff6-4e2c7d2e0637-image.png
      189e7576-89b3-4c82-a3af-228d4f46ede7-image.png

      1 1 Reply Last reply Reply Quote 3
      • 1
        158****8051 @180****8014 last edited by

        @180-8014 学到了,多谢

        1 Reply Last reply Reply Quote 0
        • 1
          180****8014 @158****8051 last edited by

          @158-8051
          好文章,结合平台的官方文章“执行训练并自动上传结果后关机”,用起来更舒服。

          训练完自动关机停止计费,并保存数据,发邮件通知。妙的

          https://gpushare.com/docs/best_practices/train/#upload

          1 1 Reply Last reply Reply Quote 2
          • First post
            Last post