我正在處理來自節的信息,其中一個目標是檢查是否有錯誤並通過電子郵件發送通知。發送電子郵件與節日誌信息
我已經能夠做的就是捕捉錯誤(或者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