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

View file

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