-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmessage.py
62 lines (46 loc) · 1.65 KB
/
sendmessage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# encoding: utf-8
'''
Created on Dec 3, 2012
@author: vencax
#install:
#--------
sudo pip install git+git://github.com/vencax/dslib.git
sudo pip install git+git://git.nic.cz/sudsds/
usage:
python sendmessage.py --username fjdsakj --pwd dsfafafdasdf \
-a /home/vencax/tosend.txt -a /home/vencax/another.pdf \
DSadresaUradu "oznameni uradu"
'''
from datoveschranky import sendmessage
if __name__ == "__main__":
import logging
from optparse import OptionParser
parser = OptionParser(usage='''\
python %prog [options] [recipient] [subject]
recipient - adresa DS prijemce
subject - predmet DS''')
parser.add_option('-u', '--username', action='store', dest='uname',
help='uzivatelske jmeno k tvoji DS',)
parser.add_option('-p', '--pwd', action='store', dest='pwd',
help='heslo k tvoji DS',)
parser.add_option('-a', '--attachement', action='append',
dest='attachements',
help='create a XHTML template instead of HTML')
(options, args) = parser.parse_args()
if len(args) != 2:
parser.error('wrong number of arguments')
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds').setLevel(logging.ERROR)
recpt_box_id, subj = args
# load attachements
attchs = []
for a in options.attachements:
attchs.append(sendmessage.load_attachement(a))
try:
reply = sendmessage.send(recpt_box_id, options.uname,
options.pwd, subj, attchs)
print reply.status
print "Message ID is:", reply.data
except Exception, e:
print str(e)