Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- from sys import argv
- import smtplib, email
- import ConfigParser, os
- config = ConfigParser.SafeConfigParser({'smtphost': 'localhost', 'smtpuser':'', 'smtppass':'', 'forwardto':''})
- config.read(['/etc/smtpclient.ini', os.path.expanduser('~/.smtpclient.ini')])
- if config.has_section('smsdmailforward'):
- section = 'smsdmailforward'
- else:
- try:
- section=config.sections()[0]
- except IndexError:
- section = 'DEFAULT'
- smtphost = config.get(section, 'smtphost')
- smtpuser = config.get(section, 'smtpuser')
- smtppass = config.get(section, 'smtppass')
- forwardto = config.get(section, 'forwardto')
- if (len(argv) < 2 or forwardto == ''):
- print "smsdmailforward.py "
- print ""
- print "An event handler script for smstools. Forwards SMS via SMTP."
- exit(0)
- statuscode = argv[1]
- smsfilename = argv[2]
- if (statuscode == 'RECEIVED'):
- smsfile = open(smsfilename)
- msg = email.message_from_string(smsfile.read())
- msg['Original-From'] = msg['From']
- msg['To'] = forwardto
- if msg['Alphabet'] == 'ISO':
- msg['Content-Type'] = 'text/plain; charset=ISO-8859-15'
- server = smtplib.SMTP(smtphost)
- server.ehlo()
- server.starttls()
- server.ehlo()
- if (smtpuser!='' and smtppass != ''):
- server.login(smtpuser, smtppass)
- server.sendmail('mailcatch-forwarder@localhost', forwardto, msg.as_string())
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement