Send e-mails on order completion (#27)

This commit is contained in:
Raphael Michel
2015-04-01 10:30:07 +02:00
parent 8a81d4859d
commit 16244bd69c
9 changed files with 105 additions and 2 deletions

51
src/pretix/base/mail.py Normal file
View File

@@ -0,0 +1,51 @@
import logging
from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import get_template
from django.utils import translation
from pretix.base.models import User, Event
logger = logging.getLogger('pretix.base.mail')
def mail(user: User, subject: str, template: str, context: dict, event: Event=None):
"""
Sends out an email to a user.
:param user: The user this should be sent to.
:param subject: The e-mail subject. Should be localized.
:param template: The filename of a template to be used. It will
be rendered with the recipient's locale.
:param context: The context for rendering the template.
:param event: The event, used for determining the sender of the e-mail
:return: ``False`` on obvious failures, like the user having to e-mail
address, ``True`` otherwise. ``True`` does not necessarily mean that
the email has been sent, just that it has been queued by the e-mail
backend.
"""
if not user.email:
return False
_lng = translation.get_language()
translation.activate(user.locale or settings.LANGUAGE_CODE)
tpl = get_template(template)
body = tpl.render(context)
sender = event.settings.get('mail_from') if event else settings.MAIL_FROM
email = EmailMessage(
subject, body, sender,
to=[user.email]
)
try:
email.send(fail_silently=False)
return True
except Exception:
logger.exception('Error sending e-mail')
return False
finally:
translation.activate(_lng)

View File

@@ -248,6 +248,16 @@ class BasePaymentProvider:
"""
return None
def order_pending_mail_render(self, order: Order) -> str:
"""
After the user submitted his order, he or she will receive a confirmation
e-mail. You can return a string from this method if you want to add additional
information to this e-mail.
:param order: The order object
"""
return ""
def order_pending_render(self, request: HttpRequest, order: Order) -> str:
"""
If the user visits a detail page of an order which has not yet been paid but

View File

@@ -4,6 +4,7 @@ import decimal
import dateutil.parser
from django.db.models import Model
from django.conf import settings
from versions.models import Versionable
@@ -14,6 +15,7 @@ DEFAULTS = {
'attendee_names_required': 'False',
'reservation_time': '30',
'last_order_modification_date': None,
'mail_from': settings.MAIL_FROM,
}