mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Change attach_inline_image default domain from hostname to "inline".
This avoids problems with ESPs that don't distinguish *Content-ID* from attachment filename, where a local hostname ending in ".com" could cause Gmail to block messages sent with inline attachments. (Mailgun, Mailjet, Mandrill and SparkPost have APIs affected by this.) Fixes #112.
This commit is contained in:
31
tests/test_message.py
Normal file
31
tests/test_message.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.test import SimpleTestCase
|
||||
from mock import patch
|
||||
|
||||
from anymail.message import attach_inline_image
|
||||
|
||||
from .utils import AnymailTestMixin, sample_image_content
|
||||
|
||||
|
||||
class InlineImageTests(AnymailTestMixin, SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.message = EmailMultiAlternatives()
|
||||
super(InlineImageTests, self).setUp()
|
||||
|
||||
@patch("email.utils.socket.getfqdn")
|
||||
def test_default_domain(self, mock_getfqdn):
|
||||
"""The default Content-ID domain should *not* use local hostname"""
|
||||
# (This avoids problems with ESPs that re-use Content-ID as attachment
|
||||
# filename: if the local hostname ends in ".com", you can end up with
|
||||
# an inline attachment filename that causes Gmail to reject the message.)
|
||||
mock_getfqdn.return_value = "server.example.com"
|
||||
cid = attach_inline_image(self.message, sample_image_content())
|
||||
self.assertRegex(cid, r"[\w.]+@inline",
|
||||
"Content-ID should be a valid Message-ID, "
|
||||
"but _not_ @server.example.com")
|
||||
|
||||
def test_domain_override(self):
|
||||
cid = attach_inline_image(self.message, sample_image_content(),
|
||||
domain="example.org")
|
||||
self.assertRegex(cid, r"[\w.]+@example\.org",
|
||||
"Content-ID should be a valid Message-ID @example.org")
|
||||
Reference in New Issue
Block a user