Question

My bad. Postmark does not support inline images apparently. Solved by changing smtp-mail provider.

I'm trying to send e-mails with TurboMail using pylons.

Everything works fine, except for using embedded images in html-content. It seems that the Content-ID header for each image is being lost somewhere along the way.

This is my code:

def sendMail(to,subject,html_content,plain_content,images):
    from turbomail import Message as Mail
    mail = Mail(to=to,subject=subject)
    mail.plain = plain_content
    mail.rich = html_content

    for cid,path in images.iteritems():
        mail.embed(path,cid)

    mail.send()

In my tests the html content is:

<html>
  <header/>
  <body>
  <h1>Send images using TurboMail</h1>
  <img src="cid:img0" />
 </body>
</html>

And the images dict:

{"img0":"path/to/img0"}
Was it helpful?

Solution 2

Apparently, Postmarkapp does not support inline images.

OTHER TIPS

When you pass in both a filename and a cid, TurboMail ignores the cid and uses the basename of the file instead. I suspect your filenames have extensions and your cids do not:

{"img0":"path/to/img0.png"}

If so, the images are embedded with a cid of img0.png instead.

You could pass in an open image file instead; TurboMail will then not ignore the name:

def sendMail(to,subject,html_content,plain_content,images):
    from turbomail import Message as Mail
    mail = Mail(to=to,subject=subject)
    mail.plain = plain_content
    mail.rich = html_content

    for cid,path in images.iteritems():
        mail.embed(open(path, 'rb'), cid)

    mail.send()

I'd use marrow.mailer instead; it's the new name for the same package but the .embed method has been made a little saner in it's handling of embedded images and cids.

an earlier revision of this answer had marrow and TurboMail confused, referring to the marrow .embed signature instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top