我正在处理来自节的信息,其中一个目标是检查是否有错误并通过电子邮件发送通知。发送电子邮件与节日志信息
我已经能够做的就是捕捉错误(或者IqError或IqTimeout)和发送普通电子邮件与书面资料:
except IqTimeout:
USERNAME = 'user'
PASSWORD = 'password'
sender = '[email protected]'
receivers = '[email protected]'
message = """From: SomeGuy <[email protected]>
To: Barbara Shell <[email protected]>
Subject: Alert of an Error
This is a test e-mail message: IqTimeout
"""
smtpObj = smtplib.SMTP('smtp.sendmail.net', 123)
smtpObj.login(USERNAME, PASSWORD)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
我也tryed打印日志,从信息的“错误”节,但只得到了一个字段:
logging.error("Could not register account. Error code: %s" %e.iq['error']['code'])
我要的是错误的信息,形成我的节被发送到电子邮件,基本上可以像这样的东西去:
To: [email protected]
From: [email protected]
Subject: Alert of an Error
This is your error:
RECV: <iq to="[email protected]/36457242971338462713453506" from="chat.test.net" id="3" type="error"><oo xmlns="http://chat.net/profile" /><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>
我正在写python。如果您需要更多信息,我会更愿意回答!
在此先感谢!
问候,
您使用的是什么XMPP库? – MattJ
使用sleekxmpp – BarbSchael