0

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"}
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Carl
  • 740
  • 8
  • 18

2 Answers2

0

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I don't have any extension on the file. I've tried the suggestion above but it still seems like the Content-ID is missing. This is the header of the received in gmail: `Content-Type: image/png; name="img0" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="img0"` I will try to change to marrow.mailer and see if it works better :) – Carl Jun 26 '12 at 09:25
  • Looking at the TurboMail 3.0.3 source code, the `Content-ID` header is *always* generated. What version are you using? – Martijn Pieters Jun 26 '12 at 09:28
  • I'm using 3.0.3 and you are right, the Content-ID is always generated in the embed method. Weird, because when the mail arrives there is no Content-ID. – Carl Jun 26 '12 at 09:42
  • Run `python -m smtpd -n -c DebuggingServer localhost:8025` to create a debugging SMTP server, it'll echo to stdout any email message you send to it (do not forget to configure your web server to send mail there). It should show you the full mail body sent to help debug this. – Martijn Pieters Jun 26 '12 at 09:45
  • According to the output from the smtp-server the Content-ID is there. Next up is to try marrow.mailer. – Carl Jun 26 '12 at 10:33
  • @carcel: If the Content-ID is there then the error is further up your mail infrastructure, and I am not sure marrow is going to fix that. Mail client, mail server, they could all be implicated here. – Martijn Pieters Jun 26 '12 at 10:34
  • After playing around a bit more with the smtp-server I got it working. Apparently Postmark does not support inline images. Thanks for the help! – Carl Jun 27 '12 at 06:47
0

Apparently, Postmarkapp does not support inline images.

Carl
  • 740
  • 8
  • 18