|
@@ -9,14 +9,13 @@ import sentry
|
|
|
|
|
|
from django.conf import settings
|
|
|
from django.core.urlresolvers import reverse
|
|
|
-from django.template.loader import render_to_string
|
|
|
from django.utils.safestring import mark_safe
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
from sentry.models import User, UserOption
|
|
|
from sentry.plugins import register
|
|
|
from sentry.plugins.bases.notify import NotificationPlugin
|
|
|
from sentry.utils.cache import cache
|
|
|
-from sentry.utils.email import MessageBuilder
|
|
|
+from sentry.utils.email import MessageBuilder, group_id_to_email
|
|
|
from sentry.utils.http import absolute_uri
|
|
|
|
|
|
NOTSET = object()
|
|
@@ -33,8 +32,8 @@ class MailPlugin(NotificationPlugin):
|
|
|
project_conf_form = None
|
|
|
subject_prefix = settings.EMAIL_SUBJECT_PREFIX
|
|
|
|
|
|
- def _send_mail(self, subject, body, html_body=None, project=None,
|
|
|
- headers=None, fail_silently=False):
|
|
|
+ def _send_mail(self, subject, template=None, html_template=None, body=None,
|
|
|
+ project=None, headers=None, context=None, fail_silently=False):
|
|
|
send_to = self.get_send_to(project)
|
|
|
if not send_to:
|
|
|
return
|
|
@@ -43,9 +42,11 @@ class MailPlugin(NotificationPlugin):
|
|
|
|
|
|
msg = MessageBuilder(
|
|
|
subject='%s%s' % (subject_prefix, subject),
|
|
|
+ template=template,
|
|
|
+ html_template=html_template,
|
|
|
body=body,
|
|
|
- html_body=html_body,
|
|
|
headers=headers,
|
|
|
+ context=context,
|
|
|
)
|
|
|
msg.send(send_to, fail_silently=fail_silently)
|
|
|
|
|
@@ -66,8 +67,14 @@ class MailPlugin(NotificationPlugin):
|
|
|
project.name.encode('utf-8'),
|
|
|
alert.message.encode('utf-8'),
|
|
|
)
|
|
|
- body = self.get_alert_plaintext_body(alert)
|
|
|
- html_body = self.get_alert_html_body(alert)
|
|
|
+ template = 'sentry/emails/alert.txt'
|
|
|
+ html_template = 'sentry/emails/alert.html'
|
|
|
+
|
|
|
+ context = {
|
|
|
+ 'alert': alert,
|
|
|
+ 'link': alert.get_absolute_url(),
|
|
|
+ 'settings_link': self.get_notification_settings_url(),
|
|
|
+ }
|
|
|
|
|
|
headers = {
|
|
|
'X-Sentry-Project': project.name,
|
|
@@ -75,26 +82,14 @@ class MailPlugin(NotificationPlugin):
|
|
|
|
|
|
self._send_mail(
|
|
|
subject=subject,
|
|
|
- body=body,
|
|
|
- html_body=html_body,
|
|
|
+ template=template,
|
|
|
+ html_template=html_template,
|
|
|
project=project,
|
|
|
fail_silently=False,
|
|
|
headers=headers,
|
|
|
+ context=context,
|
|
|
)
|
|
|
|
|
|
- def get_alert_plaintext_body(self, alert):
|
|
|
- return render_to_string('sentry/emails/alert.txt', {
|
|
|
- 'alert': alert,
|
|
|
- 'link': alert.get_absolute_url(),
|
|
|
- })
|
|
|
-
|
|
|
- def get_alert_html_body(self, alert):
|
|
|
- return render_to_string('sentry/emails/alert.html', {
|
|
|
- 'alert': alert,
|
|
|
- 'link': alert.get_absolute_url(),
|
|
|
- 'settings_link': self.get_notification_settings_url(),
|
|
|
- })
|
|
|
-
|
|
|
def get_emails_for_users(self, user_ids, project=None):
|
|
|
email_list = set()
|
|
|
user_ids = set(user_ids)
|
|
@@ -172,43 +167,35 @@ class MailPlugin(NotificationPlugin):
|
|
|
|
|
|
link = group.get_absolute_url()
|
|
|
|
|
|
- body = self.get_plaintext_body(group, event, link, interface_list)
|
|
|
+ template = 'sentry/emails/error.txt'
|
|
|
+ html_template = 'sentry/emails/error.html'
|
|
|
|
|
|
- html_body = self.get_html_body(group, event, link, interface_list)
|
|
|
+ context = {
|
|
|
+ 'group': group,
|
|
|
+ 'event': event,
|
|
|
+ 'link': link,
|
|
|
+ 'interfaces': interface_list,
|
|
|
+ 'settings_link': self.get_notification_settings_url(),
|
|
|
+ }
|
|
|
|
|
|
headers = {
|
|
|
'X-Sentry-Logger': event.logger,
|
|
|
'X-Sentry-Logger-Level': event.get_level_display(),
|
|
|
'X-Sentry-Project': project.name,
|
|
|
'X-Sentry-Server': event.server_name,
|
|
|
+ 'X-Sentry-Reply-To': group_id_to_email(group.pk),
|
|
|
}
|
|
|
|
|
|
self._send_mail(
|
|
|
subject=subject,
|
|
|
- body=body,
|
|
|
- html_body=html_body,
|
|
|
+ template=template,
|
|
|
+ html_template=html_template,
|
|
|
project=project,
|
|
|
fail_silently=fail_silently,
|
|
|
headers=headers,
|
|
|
+ context=context,
|
|
|
)
|
|
|
|
|
|
- def get_plaintext_body(self, group, event, link, interface_list):
|
|
|
- return render_to_string('sentry/emails/error.txt', {
|
|
|
- 'group': group,
|
|
|
- 'event': event,
|
|
|
- 'link': link,
|
|
|
- 'interfaces': interface_list,
|
|
|
- })
|
|
|
-
|
|
|
- def get_html_body(self, group, event, link, interface_list):
|
|
|
- return render_to_string('sentry/emails/error.html', {
|
|
|
- 'group': group,
|
|
|
- 'event': event,
|
|
|
- 'link': link,
|
|
|
- 'interfaces': interface_list,
|
|
|
- 'settings_link': self.get_notification_settings_url(),
|
|
|
- })
|
|
|
-
|
|
|
|
|
|
# Legacy compatibility
|
|
|
MailProcessor = MailPlugin
|