xsingyichuan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have been trying to construct a mime email from constituent parts held in external DB using Email::Stuffer. The basics are working fine, but I cannot seem to get it to add the Content-ID header on attachments which is required by the app that will be holding mime version of mail.

Am I using the wrong incantation or does anyone know if this module does not support Content-ID as an attachment header?

Stripped back code :

my $email = Email::Stuffer->to('Simon Cozens<simon@somewhere.jp>') ->from('Santa@northpole.org') ->text_body("You've been good this year. No coal for you.") ->attach($getMessage_obj->getFileData,content_type => 'image/anc', disposition => "anc", name => 'image.anc', Id => 'anc-id') ->email; my $email_str = $email->as_string; print $email_str;

Output confirms first three headers recognised, but content id is not set

... --1394297894.A8F240.2176 Date: Sat, 8 Mar 2014 16:58:14 +0000 MIME-Version: 1.0 Content-Type: image/anc; name="image.anc" Content-Transfer-Encoding: base64 Content-Disposition: anc iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAAXNSR0IArs4c6QAAAAlwSF +lzAAAO ...

Lot's of Google has not turned up anything relevant, I've tried many variations instead of Id, such as content-id, cid etc to no avail.

Thanks in advance
Adrian

Platform Win7, ActiveState Perl 5.16.3
Email Stuffer 0.009

Replies are listed 'Best First'.
Re: Email::Stuffer->attach cannot set content-id header?
by zentara (Cardinal) on Mar 08, 2014 at 19:34 UTC
    See JMailer. In his code, he shows all the headers needed. Possibly you don't give other headers required for a Content-ID to be succesfull.
    $encodedImage = ''; # $encodedImage = "--__Middle-Boundary__\n"; $encodedImage .= "Content-Type: image/$type\; name=\"$cleanName\"\n"; + # <----- !!!!!! $encodedImage .= "Content-Transfer-Encoding: base64\n"; $encodedImage .= "Content-Disposition: inline; filename=\"$cleanName\" +\n"; $encodedImage .= "Content-ID: <img$count>"; $encodedImage .= "\n\n"; $encodedImage .= $self->_encode64(\$inline_image);

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Email::Stuffer->attach cannot set content-id header?
by McA (Priest) on Mar 09, 2014 at 00:37 UTC

    Hi Adrian,

    IMHO you can't do what you want with Email::Stuffer.

    Email::Stuffer is a convenient wrapper around Email::MIME. So, you can build special mails with Email::MIME on your own.

    I'm not sure in your case. But Content-ID is often used in multipart/related mails to refer to a part in that mail. Email::Stuffer is IMHO only capable to create multipart/mixed mails.

    McA

      Hi, thanks for both replies. After a bit more playing I'm inclined to agree with McA. Looking at an email I'm trying to emulate it is indeed multipart/related.

      Looks like I'll need to write something lower level.

      Thanks again
      Adrian

        Hi Adrian,

        have a look at the following snippet whether it is helpful for your solution:

        #!/usr/bin/env perl use strict; use warnings; use 5.010; use Email::MIME; use MIME::Base64; use File::Slurp; my $html = <<EOF; <html> <head> <title>Testmail</title> </head> <body> <p>This is a test html mail with an inline graphic.<br/> <img src="cid:logo" alt="Logo" width="158px" height="70px" />< +/p> </body> </html> EOF # read the file my $filename = 'logo.png'; # take filename of a small 158x70 png my $image = read_file($filename, binmode => ':raw'); my $image_encoded = encode_base64($image); my $mail_part = Email::MIME->create( attributes => { content_type => "text/html", charset => "UTF-8", encoding => "quoted-printable", }, body_str => $html, ); my $jpeg_part = Email::MIME->create( header_str => [ 'Content-ID' => '<logo>', 'Content-Disposition' => 'inline', ], attributes => { content_type => "image/png", encoding => "base64", }, body => $image, ); my $mail = Email::MIME->create( header_str => [ 'To' => 'yourmail@yourdomain.de', 'From' => 'McA@perlmonks.org', 'Subject' => 'Testmail with inline graphic', ], attributes => { content_type => "multipart/related", }, parts => [ $mail_part, $jpeg_part, ], ); say $mail->as_string;

        Best regards
        McA