46 lines
1.0 KiB
Python
Executable File
46 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
import gtk
|
|
import smtplib
|
|
|
|
def get_config(fname):
|
|
config = {}
|
|
fh = open(fname, 'r')
|
|
script = fh.read()
|
|
fh.close()
|
|
exec(script, config)
|
|
return config
|
|
|
|
def main(argv):
|
|
config = {}
|
|
if len(argv) != 3:
|
|
sys.stderr.write('Usage: %s <config-file> <note>\n' % argv[0])
|
|
return 1
|
|
config = get_config(argv[1])
|
|
message = argv[2]
|
|
if not ('server' in config and 'port' in config and 'user' in config
|
|
and 'password' in config and 'to_addr' in config
|
|
and 'from_addr' in config):
|
|
sys.stderr.write('Missing a config field!\n')
|
|
return 1
|
|
|
|
if message == '':
|
|
return 0
|
|
|
|
msg = '''From: <%s>
|
|
To: <%s>
|
|
Subject: %s
|
|
|
|
<EOM>
|
|
''' % (config['from_addr'], config['to_addr'], message)
|
|
smtp = smtplib.SMTP_SSL(config['server'], config['port'])
|
|
smtp.login(config['user'], config['password'])
|
|
smtp.sendmail(config['from_addr'], config['to_addr'], msg)
|
|
smtp.quit()
|
|
|
|
return 0
|
|
|
|
sys.exit(main(sys.argv))
|