improve sendmail function.

This commit is contained in:
Thomas L 2018-03-29 02:40:22 +02:00
parent 10fb150c21
commit 78331212e6
2 changed files with 11 additions and 7 deletions

View file

@ -10,6 +10,10 @@ from session import SessionPlugin
from mastodon import Mastodon
def url(route):
'%s://%s/%s' % (request.urlparts.scheme, request.urlparts.netloc, route)
@get('/')
@view('template/propaganda.tpl')
def propaganda():
@ -30,11 +34,9 @@ def register_post():
try:
sendmail(
email,
"[Ticketfrei] Confirm your account",
"Complete your registration here: %s://%s/confirm/%s" % (
request.urlparts.scheme,
request.urlparts.netloc,
db.user_token(email, password)
"Confirm your account",
"Complete your registration here: %s" % (
url('confirm/%s' % db.user_token(email, password))
)
)
return dict(info='Confirmation mail sent.')

View file

@ -9,8 +9,10 @@ import smtplib
from socket import getfqdn
import ssl
logger = logging.getLogger(__name__)
class Mailer(object):
"""
Maintains the connection to the mailserver and sends text to users.
@ -71,9 +73,9 @@ class Mailer(object):
def sendmail(to, subject, body=''):
msg = MIMEMultipart()
msg['From'] = '%s@%s' % (getuser(), getfqdn())
msg['From'] = 'Ticketfrei <%s@%s>' % (getuser(), getfqdn())
msg['To'] = to
msg['Subject'] = subject
msg['Subject'] = '[Ticketfrei] %s' % (subject, )
msg.attach(MIMEText(body))
with smtplib.SMTP('localhost') as smtp: