I'm using perl to try to send e-mail consisting of ".gif" and ".jpg" files in the body of the e-mail. I don't want them to be sent as attachments. I tried using Mail::Sendmail but it only send the files as attachments.

(Additional emphasis by me)

I personally believe that it is technically impossible. What you can do it to concoct up a HTML-formatted email with <img> tags which refer to attached images through a cid URI scheme.

Also, I'm not terribly familiar with the myriad of ?mail* modules, but Mail::Sendmail is a nothing but a "simple platform independent mailer" and is last updated as of 2003: this may not be a problem, as much as a hint that it is stable and good enough not to need any further development, however it also suggests you may look for something better!

I then tried MIME::Lite and that looked like I might be working in the right direction but I got stuck when it said there wasn't any sendmail attachment on the windoze system.

MIME:Lite is certainly capable of doing what you need: thus you should show us some code proving it fails to work for you. As a hint, however, take the following snippet:

use strict; use warnings; use 5.010; use MIME::Lite; use HTML::TreeBuilder; # or what you like most use File::Basename; use File::Type; # ... sub makemsg { my (%id, %saw); (my $tree=HTML::TreeBuilder->new)->parse_file(shift); for my $img ($tree->look_down(_tag => 'img')) { defined(my $imgname=$img->attr('src')) or warn "[$0] Warning: img tag with no src attribute!" and next +; unless($id{$imgname}) { # not necessary, but I prefer it like that! (my $id=basename $imgname) =~ s/_*[^\w]+/_/g; $id++ while exists $saw{$id}; $saw{$id}++; $id{$imgname}=$id; } $img->attr(src => "cid:$id{$imgname}"); } my $msg=MIME::Lite->new( To =>'someone@example.org', Subject =>'HTML with in-line images!', Type =>'multipart/related'); $msg->attach( Type => 'text/html', Data => $tree->as_HTML); $tree->delete; # However ugly, it's necessary! my $ft=File::Type->new; for (keys %id) { $msg->attach( Type => $ft->checktype_filename($_) // 'image/xyz', Id => $id{$_}, Path => $_); } $msg; }

Come to think of it, it may be the basis of a HTML2MHTML converter... (That's how I tested it: who said exploder is totally useless?) Caveat: this assumes but does not check, that all images are stored locally on your system so there many refinements to do, or you may want to download them if they're not local, and so on.

However, there must be modules already to do the same in an easier, dwimmier way and a simple cpan search found out one such module, namely HTML::Mail, which also seems updated quite recently.

Notice that if you send HTML-formatted mail, you should include a pure text version of the same mail: H::M lets you add a text part to it, period. But then you can do the conversion yourself, and I recommend using HTML::FormatText::WithLinks. I can also point you towards an article describing how to use MIME::Lite::TT::HTML to send HTML-formatted email created with the aid of a templating system, which you may like ot not as an idea... and the latter module does use precisely H::FT::WL to create a pure text version of the mail if one is not specified manually.

Conclusion: you have quite a lot of choices!

--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re: composing e-mail in active perl by blazar
in thread composing e-mail in active perl by jdarfler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.