6:eaca36ce092b default tip
Anton Shestakov <av6@dwimlabs.net>, Fri, 23 Aug 2019 22:27:47 +0700
use TLS 1.2 because it's modern, and that's what clients should use

previous change 0:6d62d30434ab

xmpp-headline.py

Permissions: -rw-r--r--

Other formats: Feeds:
#!/usr/bin/env python
from __future__ import print_function
import sys
import sleekxmpp
class SendMsgBot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, recipient, efrom, esubject):
super(SendMsgBot, self).__init__(jid, password)
self.recipient = recipient
self.efrom = efrom
self.esubject = esubject
self.add_event_handler('session_start', self.start)
import ssl
self.ssl_version = ssl.PROTOCOL_TLSv1_2
def start(self, event):
print('sending message...')
self.send_message(
mtype='headline',
mto=self.recipient,
msubject='New email: %s' % self.esubject,
mbody='%s from %s' % (self.esubject, self.efrom))
print('sent.')
print('disconnecting...')
self.disconnect(wait=True)
print('disconnected.')
def main():
jid = 'emailbot@example.com'
password = 'hunter2'
to = 'john@example.com'
efrom = sys.argv[1] or '(unknown)'
esubject = sys.argv[2] or '(no subject)'
xmpp = SendMsgBot(jid, password, to, efrom, esubject)
print('connecting...')
if xmpp.connect():
print('processing...')
xmpp.process(block=True)
print('done.')
else:
print('connection failed.')
sys.exit(1)
if __name__ == '__main__':
main()