自动化测试之生成测试脚本自动发送邮件(554异常和connection unexpectedly closed)

今天在学习发送邮件的时候遇到了几个问题,这边一是记录一下 二是给同样遇到问题的同学解惑
这里写图片描述
1、这个问题我发生的原因是163邮箱 SMTP协议未开启,如果已开启还是报这个错误尝试重新开启一次。开启之后是设置变量也好还是input密码记住不能用163邮箱的登录密码,而是需要使用设置的客户端授权密码。以上针对我出现的这个问题得到了解决。
2、看廖雪峰的简单邮件实例发现自己运行后报554,官方解释就是被屏蔽了。

from email.mime.text import MIMEText
import smtplib
from email.header import Header

msg = MIMEText('真的不知道是什么原因', 'plain', 'utf-8')
# 输入Email地址和口令:
from_addr = 'xxx@163.com'
password = '客户端授权密码'

# 输入收件人信息:
to_addr = 'xxx@qq.com'
# 输入SMTP服务器地址:
smtp_server = 'smtp.163.com'

server = smtplib.SMTP(smtp_server, 25)  # SMTP协议默认端口是25
server.set_debuglevel(1)  # 打印出和SMTP服务器交互的所有信息
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
print('success')

这样的163–>qq 邮箱的(别的我没有试过)是不会成功的,一直报554的错误。我网上找了几个办法好像都行不通。后来我仔细琢磨了一下屏蔽原因会不会是右键内容太过单调而导致的呢。于是我新增了几个属性

msg['Subject'] = Header('放假通知', 'utf-8')
msg['From'] = 'xxx@163.com'
msg['To'] = "xxx@qq.com"

运行成功。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Remote Task Manager: readme ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please read this file carefully (especially the "Installation" chapter) before installing the program to your computer. IMPORTANT! If you obtained RTM not from our web page, but from another source (CD or a software library), please visit our home page where you might find a later version. Contents ~~~~~~~~ Program information Company information Description Installation (!) Registration Copyright and license Technical support Program information ~~~~~~~~~~~~~~~~~~~ Program Archive Name: rtm.zip Program Name: Remote Task Manager Program Version: 3.8.2 Program Release Date: September 22, 2005 Target OS: Windows NT 4.0, Windows 2000, Windows XP, Windows Server 2003 Platform: Intel x86 Brief Description: The remote manager for tasks, processes, services, devices, shares and events Software type: 30-day trial Company information ~~~~~~~~~~~~~~~~~~~ Company Name: SmartLine Inc Author Name: Ashot Oganesyan Contact E-mail Address: support@protect-me.com Contact WWW URL: http://www.protect-me.com Description ~~~~~~~~~~~ Remote Task Manager (RTM) is a systems control interface that can be run from any remote Windows NT/2000/XP computer. This lets Systems Administrators control most aspects of a remote environment. The simple-to-use, tabbed interface separates applications, services, devices, processes, events, shared resources and performance monitor, making each of these very easy to manage. With RTM you can: - Monitor all running tasks, processes, services, devices, shared resources and events on remote computers - Watch features of running tasks (the handle of the main window, process ID, etc.) - Watch features of running processes (process ID, CPU time, privileges used, memory, priority, etc.) - See which process is associated with a selected task - See which process is associated with a selected service - End a selected task correctly - Terminate a selected process at any time - Change priority of a selected process - Control which CPUs the process will be allowed to execute on - Stop, start, restart, pause and continue any selected service or device - Change startup parameters of a service or a device (name, account, startup type, dependencies, etc.) - Change service's repair parameters on Windows 2000/XP - Watch dependent services or devices - Adjust service's and device's security (permissions, auditing and owner) - Clear event logs - Archive event logs - Monitor a dynamic overview of the computer's performance (CPU and memory usage) - Manage shared resources on remote computers - Monitor all open TCP and UDP ports - Shut down and reboot remote computers - Create processes on remote computers - Lock computers remotely - And much more Installation ~~~~~~~~~~~~ To install RTM you MUST have administrative privileges. Run "setup.exe". You'll need to select the target directory for the install. If you wish to install RTM without an user intervention you should run RTM Setup with the /s parameter (e.g. "c:\setup.exe /s"). This gives an install that can be used from within a batch file. There is a special configuration file for silent setup: rtm.ini. With this file, you can customize the RTM installation parameters. For example: 1. "Install" parameters: Service - RTM Service and its related files will be installed Manager - RTM Manager and its related files will be installed Documents - documentation (readme.txt, register.txt) will be installed To specify a destination directory for RTM, you can supply the parameter InstallDir If you have the registration key-file for RTM, you can specify a directory with this file in the parameter RegFileDir 2. "Misc" parameters: Run - this parameter is used to launch an application or execute a batch file after a successful install. Registration ~~~~~~~~~~~~ See "register.txt" file. Copyright and license ~~~~~~~~~~~~~~~~~~~~~ See "license.txt" file. Technical support ~~~~~~~~~~~~~~~~~ See "contacts.txt" file. Copyright(c) 1998-2005 SmartLine Inc. All rights reserved. Remote Task Manager is a registered trademark of SmartLine Inc.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值