My approach requires using MIME::Lite to send an email (via the ZM_NEW_MAIL_MODULES selection).
I'm going to start by putting the modified zmfilter.pl code here, because I think it's easiest to explain in reverse order of how it is coded.
Code: Select all
if ( ZM_NEW_MAIL_MODULES )
{
### Create the multipart container
my $mail = MIME::Lite->new (
From => ZM_FROM_EMAIL,
To => ZM_EMAIL_ADDRESS,
Subject => $subject,
Type => "multipart/mixed"
);
### Create an image tag for each attachment
my $attachment_count = 0;
my $img_tags = "";
foreach my $attachment ( @attachments )
{
$attachment_count++;
$img_tags .= qq {<img src="cid:inline_image$attachment_count"><br>};
}
### Add an html message part
$mail->attach (
Type => "text/html",
Data => qq {<body>$img_tags<br>$body</body>}
);
### Add the text message part
$mail->attach (
Type => "TEXT",
Data => $body
);
### Add the attachments
### Add the counter to create an image Id
### Note that is must be declared "my" or else it will
### be considered global and cause the entire zmfilter.pl to fail
$attachment_count = 0;
foreach my $attachment ( @attachments )
{
Info( "Attaching '$attachment->{path}\n" );
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Id => ('inline_image' . ++$attachment_count),
Disposition => "attachment"
);
}
### Send the Message
MIME::Lite->send( "smtp", ZM_EMAIL_HOST, AuthUser=>'you@yourdomain.com', AuthPass=>'yourpass', Timeout=>60 );
$mail->send();
}
That ID can be referenced by an html image tag, using the CID identifier. You'll note that earlier in the code I loop over all the attachments and build an image tag for each image. Immediately after that, I just add an html message part. Note that I put my $img_tags and the standard $body with a <body> tag section.
I then went to the options screen of ZM and simply added <br> to the end of each line such that they would appear correctly in an html message. If the message is plain text, I see the extra "<br>" at the end of each line, but I can deal with that. In theory I could remove the plain text message part, but it doesn't hurt to keep and just shows up as a text attachment when the email client views the html. For clients that don't show html messages, you still get the plain text. Seems like the best of both worlds for minimal overhead.
I don't believe this addition of an Id causes any problems with plain text emails and attachments. Consequently it's just the creation of the image tags and the html message part that could be wrapped in an "if" statement which executes dependent upon a new configuration option (much like the ZM_NEW_EMAIL_MODULES option).
Finally note that I'm using the AuthUser and AuthPass to authenticate against my SMTP server. I posted that a while back, and I still believe those fields ought to become standard in the email options screen.