Email attachments in Django1.10 failing

27 views
Skip to first unread message

E kamande

unread,
Feb 1, 2017, 8:10:53 PM2/1/17
to Django users
Hi Kindly need help to be able attaching a logo and a pdf when emailing, I have been following this great articles 1 and 2  but it seems am always getting something wrong.
Here is a sample code of mine , It fails the following error  "<email.mime.image.MIMEImage instance at 0x7f7156a88d88> is not JSON serializable"

        connection = mail.get_connection()
        msg = EmailMultiAlternatives(
            subject, from_email, receiver)

        msg.attach_alternative(mail_body, 'text/html')
        image = MIMEImage(insurer.company_logo.read())
        image.add_header('Content-ID', '<{}>'.format('logo.png'))

        msg.attach('logo.png',image, 'image/png')
        msg.send()
        connection.send_messages([msg])



Tim Graham

unread,
Feb 2, 2017, 10:58:17 AM2/2/17
to Django users
Could you include a complete traceback that shows which line is causing the error?
Reply all
Reply to author
Forward
0 new messages