zoukankan      html  css  js  c++  java
  • 10.Selenium+Python+任务计划程序实现定时发送邮件

    一.python具体代码实现

    # coding=utf-8
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
    
    # 发送html格式的邮件
    
    
    sender = "发送方邮箱地址"  # 发送邮箱
    
    receiver = "接收方邮箱地址"  # 接收邮箱
    
    subject = "自动化测试"   # 发送邮件主题
    
    smtpserver = "smtp.qq.com"   # 发送邮箱服务器
    
    username = "发送方邮箱地址"   # 发送邮箱用户
    password = "tzdulnopczzsfhdb"    # 发送邮箱用户的IMAP地址,根据邮箱不同其密码也不同
    
    
    msg = MIMEText("<html><h1>自动化测试</h1></html>", "html", "utf-8")   # HTML形式的邮件
    msg["Subject"] = Header(subject, "utf-8")
    
    smtp = smtplib.SMTP_SSL(smtpserver, 465)
    smtp.login(username, password)
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()
    

     (1)其password是QQ邮箱的IMAP/SMTP服务授权码,需要获取,可以百度教程获取

    二.新建脚本为autoTest.bat

     注:python脚本位置最好为根目录,不知道原因,第一次时将其放在别的字目录下,但是双击脚本没有执行程序,替换为跟目录后正常

    三.任务计划程序

    (1)在开始-程序,打开“任务计划程序”

    (2)创建任务,在“常规”中输入名称

    (3)在“触发器-新建”,根据自己的需求,指定在几点开始,其中多少分钟后发送

    (4)在“操作-新建”,选择bat文件,点击【确定】即可

     (5)设置完成后,在首页即可看到起计划

    四:设置后任务计划程序后,不需要手动启动程序,在指定时间内,脚本自动运行发送邮件给指定邮箱

  • 相关阅读:
    05. Spring Security 图形验证码
    Spring Security 登出
    03. Spring Security 异常处理
    02. Spring Security rememberMe
    Redirect和Forward的区别
    01. spring-security 初体验
    nextInt()和nextLine()注意点
    JavaBean
    05. Hystrix Dashboard
    bootstrap.yml 和 application.yml
  • 原文地址:https://www.cnblogs.com/android-it/p/9365835.html
Copyright © 2011-2022 走看看