我的电子邮件脚本基于Fine Frog的这个脚本。我正在使用这个脚本从许多使用各种 ISP 的远程机器发送 HTML 日志文件。
但是,附件并未始终如一地发送。它确实有 80% 的时间有效,但我遇到了两种奇怪的行为。第一个是根本不发送电子邮件,但会抛出您在下面看到的错误
Traceback (most recent call last):
File "/root/sapapps/reporter/usage_report.py", line 336, in ?
se.send_mail(['thinkwelldesigns@g1234.com'], cd.contact, 'dave@1234.com', report_subject, text_body, files=[report_name], bcc=[cd.tech_email])
File "/usr/lib/python2.4/site-packages/sap/send_email.py", line 61, in send_mail
mail_server.sendmail(server_addr, addresses, message.as_string())
File "/usr/lib/python2.4/smtplib.py", line 692, in sendmail
(code,resp) = self.data(msg)
File "/usr/lib/python2.4/smtplib.py", line 489, in data
self.send(q)
File "/usr/lib/python2.4/smtplib.py", line 319, in send
raise SMTPServerDisconnected('Server not connected')
smtplib.SMTPServerDisconnected: Server not connected
或者,在某些机器上,会引发此错误。
reply: '421 Command timeout, closing transmission channel\r\n'
reply: retcode (421); Msg: Command timeout, closing transmission channel
data: (421, 'Command timeout, closing transmission channel')
send: 'rset\r\n'
Traceback (most recent call last):
File "/root/sapapps/reporter/usage_report.py", line 336, in ?
se.send_mail(['thinkwelldesigns@1234.com'], cd.contact, 'dave@1234.com', report_subject, text_body, files=[report_name], bcc=[cd.tech_email])
File "/usr/lib/python2.4/site-packages/sap/send_email.py", line 61, in send_mail
mail_server.sendmail(server_addr, addresses, message.as_string())
File "/usr/lib/python2.4/smtplib.py", line 694, in sendmail
self.rset()
File "/usr/lib/python2.4/smtplib.py", line 449, in rset
return self.docmd("rset")
File "/usr/lib/python2.4/smtplib.py", line 374, in docmd
return self.getreply()
File "/usr/lib/python2.4/smtplib.py", line 348, in getreply
line = self.file.readline()
File "/usr/lib/python2.4/socket.py", line 340, in readline
data = self._sock.recv(self._rbufsize)
socket.error: (104, 'Connection reset by peer')
在第二个奇怪行为的例子中,电子邮件被正确处理,附件继续存在,但在电子邮件发送过程中,一些数据被从 HTML 附件中删除。IOW,如果你登录到远程机器,你会发现原始文件完好无损,但附件是丢失的日志条目。
我猜这些问题是不相关的问题,但是有人对如何最可靠地发送 HTML 附件有一些建议吗?
TIA,
戴夫