-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcome_mailer
executable file
·37 lines (28 loc) · 964 Bytes
/
welcome_mailer
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
#!/usr/bin/env python3
# this should not be imported
assert __name__ == '__main__'
# assure we are in the right directory, so we find our relative imports
import os
os.chdir(os.path.dirname(__file__))
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from sys import stdin
import atexit
from logging import shutdown as logging_shutdown
import mailer
import my_logging
import conf
atexit.register(logging_shutdown)
logger = my_logging.getLogger('welcome_mailer')
logger.debug("Starting welcome mailer as user %d in group %d"%(os.geteuid(),os.getgid()))
mails = []
for line in stdin:
mail,pw,name = line.strip().split(',')
valuedict = {'emailadr':mail,'password':pw,'name':name}
msg=MIMEText(conf.welcome_mail_body % valuedict)
msg['Subject'] = Header(conf.welcome_mail_subject % valuedict)
msg['From'] = Header(conf.welcome_mail_from % valuedict)
msg['To'] = mail
mails.append((msg,[mail]))
mailer.send_mails(mails)