2018-01-01 10:23:50 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-03-28 18:24:21 +00:00
|
|
|
from config import config
|
2018-01-01 10:23:50 +00:00
|
|
|
from email.mime.text import MIMEText
|
2018-01-05 10:20:07 +00:00
|
|
|
from email.mime.multipart import MIMEMultipart
|
2018-03-28 22:31:21 +00:00
|
|
|
import logging
|
2018-03-28 22:57:17 +00:00
|
|
|
from getpass import getuser
|
|
|
|
import smtplib
|
|
|
|
from socket import getfqdn
|
2018-03-28 22:31:21 +00:00
|
|
|
|
2018-03-29 00:40:22 +00:00
|
|
|
|
2018-03-28 22:33:29 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2018-01-01 10:23:50 +00:00
|
|
|
|
2018-03-29 00:40:22 +00:00
|
|
|
|
2018-10-06 00:46:54 +00:00
|
|
|
def sendmail(to, subject, city=None, body=''):
|
2018-03-28 22:57:17 +00:00
|
|
|
msg = MIMEMultipart()
|
2018-10-06 00:46:54 +00:00
|
|
|
if city:
|
|
|
|
msg['From'] = 'Ticketfrei <%s@%s>' % (city, getfqdn())
|
|
|
|
else:
|
|
|
|
msg['From'] = 'Ticketfrei <%s@%s>' % (getuser(), getfqdn())
|
2018-03-28 22:57:17 +00:00
|
|
|
msg['To'] = to
|
2018-03-29 00:40:22 +00:00
|
|
|
msg['Subject'] = '[Ticketfrei] %s' % (subject, )
|
2018-03-28 22:57:17 +00:00
|
|
|
msg.attach(MIMEText(body))
|
|
|
|
|
|
|
|
with smtplib.SMTP('localhost') as smtp:
|
|
|
|
smtp.send_message(msg)
|
|
|
|
|
|
|
|
|
2018-01-01 10:23:50 +00:00
|
|
|
# For testing:
|
|
|
|
if __name__ == '__main__':
|
2018-10-06 08:20:37 +00:00
|
|
|
sendmail(config['mail']['contact'], "Test Mail",
|
|
|
|
body="This is a test mail.")
|