Skip to content

Gmail blocks mail with inline images if sent from hostname ending in .com #112

@mansonul

Description

@mansonul
  • Anymail version = 2.2
  • ESP (Mailgun, SendGrid, etc.) = Mailgun
  • Versions of Django, python = 1.11.13, 3.6

I'm having problems sending mails to gmail accounts. If I use the attach_inline_image_file i get this from gmail:

Failed: sender@mydomain.comreceiver@gmail.com 'Email subject Server response: 552 5.7.0 This message was blocked because its content presents a potential 5.7.0 security issue. Please visit 5.7.0 https://support.google.com/mail/?p=BlockedMessage to review our 5.7.0 message content and attachment content guidelines. b12-v6si932446qtq.229 - gsmtp

I think this is happening because the image name looks like this "20180619202303.24365.655.img@domain" instead of "pic1.jpg". Is this normal? What am I doing wrong?

This is my .py file:

        message = AnymailMessage(
            subject=subject,
            body=body,
            to=recipients
        )

        cid = attach_inline_image_file(
           message,
           os.path.join(settings.ROOT_DIR, "/invitations/static/photos/2018-05-01.jpg"),
        )
        context = get_invitation_context()
        context['main_image'] = cid
        context['body'] = body
        template_html = render_to_string('invitations/invitation.html', context=context)
        message.attach_alternative(template_html, "text/html")
        message.mixed_subtype = 'related'
        message.send()

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions