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:
medmunds
2018-07-06 16:30:27 -07:00
parent 3f2c6d6917
commit e6431a62f0
4 changed files with 54 additions and 2 deletions

View File

@@ -59,6 +59,10 @@ def attach_inline_image_file(message, path, subtype=None, idstring="img", domain
def attach_inline_image(message, content, filename=None, subtype=None, idstring="img", domain=None):
"""Add inline image to an EmailMessage, and return its content id"""
if domain is None:
# Avoid defaulting to hostname that might end in '.com', because some ESPs
# use Content-ID as filename, and Gmail blocks filenames ending in '.com'.
domain = 'inline' # valid domain for a msgid; will never be a real TLD
content_id = make_msgid(idstring, domain) # Content ID per RFC 2045 section 7 (with <...>)
image = MIMEImage(content, subtype)
image.add_header('Content-Disposition', 'inline', filename=filename)