forked from miracle2k/linuxutils
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.py
More file actions
Latest commit
executable file
·47 lines (36 loc) · 1.35 KB
/
Copy pathmail.py
File metadata and controls
executable file
·47 lines (36 loc) · 1.35 KB
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
#!/usr/bin/env python
"""A very simple mail tool that I use on a Synology NAS to send email,
where an usuable "mail" command line tool doesn't seem to be available
via ipkg, in particular if I don't want to install a local SMTP server.
"""
importsys
fromoptparseimportOptionParser
importsmtplib
fromemail.mime.textimportMIMEText
defmain():
parser=OptionParser()
parser.add_option("-s", dest="subject", help="Subject")
parser.add_option("-f", dest="from_", help="From address")
parser.add_option("--host", dest="host", help="SMTP Host")
parser.add_option("--port", dest="port", help="SMTP Port", default=25)
parser.add_option("-q", dest="quiet", help="Be quiet.", default=False)
(options, recipients) =parser.parse_args()
ifnotrecipients:
print"No recipients specified."
return1
stdin=sys.stdin.read()
ifnotstdin.strip():
ifnotoptions.quiet:
print"No stdin text, not sending message."
return1
smtp=smtplib.SMTP()
smtp.connect(options.host, options.port)
forrecipientinrecipients:
msg=MIMEText(stdin)
msg['Subject'] =options.subject
msg['From'] =options.from_
msg['To'] =recipient
smtp.sendmail(options.from_, [recipient], msg.as_string())
smtp.quit()
if__name__=='__main__':
sys.exit(main() or0)