我想将smtplib导入到我写的sikuli脚本中,这样Sikuli可以在测试完成后自动发送电子邮件。
但是,我遇到一个问题,Sikuli在Python中找不到smtplib模块,我确信它已安装并位于Python27 / Lib目录中。以下是我正在使用的代码。我使用SikuliX 1.1.0和Python 2.7。
import smtplib
sender = '<email address hidden>'
receivers = ['<email address hidden>']
message = """From: From Person <email address hidden>
To: To Person <email address hidden>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('test.com.hk')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except:
print "Error: unable to send email"
当我在Sikuli IDE中运行时,它给了我:
&#34; [错误]脚本[发送]在第2行中因错误而停止 [error] ImportError(没有名为utils的模块) [错误] --- Traceback ---错误源第一行:module(function)语句46:smtplib()import email.utils [错误] ---追溯---结束--------------&#34;
有人可以帮忙吗?感谢
答案 0 :(得分:0)
您的email.py
中有一个名为sys.path
的文件正在影响标准库的email
包 - 它甚至可能是您的脚本测试
https://docs.python.org/2/library/email.html
要修复,请使用其他任何内容作为模块/文件名。
akg@limbo:~/scratch.d/20151012-stack33095084$ cat email.py
import smtplib
sender = '<email address hidden>'
receivers = ['<email address hidden>']
message = """From: From Person <email address hidden>
To: To Person <email address hidden>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('test.com.hk')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except:
print "Error: unable to send email"
akg@limbo:~/scratch.d/20151012-stack33095084$ python email.py
Error: unable to send email
Traceback (most recent call last):
File "email.py", line 1, in <module>
import smtplib
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
akg@limbo:~/scratch.d/20151012-stack33095084$ mv email.py anything_but_email.py
akg@limbo:~/scratch.d/20151012-stack33095084$ python anything_but_email.py
Error: unable to send email