0

I have installed a Sentry instance on my server, and I want to configure it to send alert emails using Mandrill and its Django integration djrill. Here's the relevant settings in the sentry.conf.py file I'm using:

EXTRA_INSTALLED_APPS = (
    'djrill',
)
EMAIL_BACKEND = 'djrill.mail.backends.djrill.DjrillBackend'

MANDRILL_API_KEY = '[... Mandril API key ...]'
DEFAULT_FROM_EMAIL = 'my-mandrill-allowed@email.address'
SERVER_EMAIL = 'my-mandrill-allowed@email.address'

And this setup works, except for the part that for some reason Mandrill doesn't allow setting the Message-Id header:

NotSupportedByMandrillError: Invalid message header 'Message-Id' - Mandrill only allows Reply-To and X-* headers

(This exception is raised by djrill, is not a response from Mandrill)

Which is set by Sentry here:

class MessageBuilder(object):
    # ...
    @cached_property
    def message_id(self):
        if self.reference is not None:
            return email_id_for_model(self.reference)

I have managed to make it work by editing that method and make it always return None, so no Message-Id header is set in the email. But I don't like to edit/patch 3rd party code and I have no idea if that header is needed elsewhere.

How to accomplish this correctly? Switching from Mandrill is not an option right now.

Thanks!

Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45

1 Answers1

0

As you can't easily change Sentry's behavior, as far as I can tell, I'd suggest implementing a subclass of DjrillBackend that removes the Message-Id header before the messages are sent. Something like (untested):

class HeaderRemovingBackend(DjrillBackend):
    def send_messages(self, email_messages):
        for message in email_messages:
            if 'Message-Id' in message.extra_headers:
                del message.extra_headers['Message-Id']
        super(HeaderRemovingBackend, self).send_messages(email_messages)
sk1p
  • 6,645
  • 30
  • 35
  • Well, I resolved it installing the latest version of Djrill. But I'm going to accept this answer because I was going to implement it if upgrading wasn't an option. Thanks! – Armando Pérez Marqués May 29 '14 at 22:59