initial version
This commit is contained in:
commit
3ae494ea4d
45
smtp-send-note.py
Executable file
45
smtp-send-note.py
Executable file
@ -0,0 +1,45 @@
|
||||
#!/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))
|
Loading…
x
Reference in New Issue
Block a user