Page 1 of 1

Embedded images fail in Thunderbird

Posted: Sun Mar 22, 2009 7:59 pm
by mike_h
I am using this code to send a multipart message.
Both Outlook and Thunderbird (2.0.0.21) display it correctly when there is no embedded image. (Both display HTML)
When I try to embed an image Thunderbird falls back to showing the plain text body and the image and the HTML part appear as separate attachments (The HTML body is called Part 1.2).

I know TB can display embedded images because if I compose a message in Outlook and send to TB it displays fine.

One difference seems to be that messages authored in Outlook or TB wrap the name and filename headers in quotes (when viewing the message source). Swift has no quotes around these values.
e.g

Code: Select all

 
Content-Type: image/png;
 name="logo.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.00070101.09080800@example.com>
Content-Disposition: inline;
 filename="logo.png"
 
Any suggestions?
Thanks,

Code: Select all

<?php
require 'Swift-4.0.3/lib/swift_required.php';
 
//Messsage
$msg = Swift_Message::newInstance();
$msg -> setSubject('See my image');
$msg -> setFrom(array('swift@example.com'));
$msg -> setTo(array('thunderbird@example.com'=>'Thunderbird Client'));
 
$msg -> setBody("This is the plain text you'll see when I try and embed an image.");
 
//Image to embed
$cid = $msg->embed(Swift_Image::fromPath('logo.png'));
$img = '<p><img src="' . $cid . '" alt="Awesome Logo" width="120" height="36"></p>';
 
// HTML body
$msg -> addPart(
    "<h1>See my logo</h1>" .
    "<p>Outlook works, Thunderbird will fall back to plain text and show the " .
    "HTML body (as Part 1.2) and the image as attachments</p>" .
    $img,
    
    'text/html'
);
 
//Transport and Mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
 
if($mailer->send($msg)) {
    echo "Message Sent";
}
 

Re: Embedded images fail in Thunderbird

Posted: Mon Mar 23, 2009 1:02 am
by Chris Corbyn
I'll give this a whirl when I get home from work and will get back to you :)

It sounds as though the parts appear in the incorrect order (Plain Text *after* the HTML part).

If you have the full message source that Swift Mailer generated you may PM it to me and I'll have a look at that too :)

Re: Embedded images fail in Thunderbird

Posted: Mon Mar 23, 2009 4:00 am
by Chris Corbyn
This is a bug, sorry about that.

Change your first setBody() to addPart() and it will work.

I'll get this fixed.

If you're awaiting the fix, watch this ticket:

http://swiftmailer.lighthouseapp.com/pr ... icket-77-2

Re: Embedded images fail in Thunderbird

Posted: Mon Mar 23, 2009 7:50 am
by mike_h
Excellent, I changed to addPart('text content', 'text/plain') and it work just as your prophecy said it would :)
Thanks for the responsiveness Chris.

I think I came up with my original code by combining the quick start reference and embedding files example.