I'm using HTML::Template for templating, MIME::Base64 for encode_base64, Email::Date::Format for email_date.

Template:

To: <!-- TMPL_VAR TO --> From: <!-- TMPL_VAR FROM --> Subject: =?UTF-8?B?<!-- TMPL_VAR SUBJECT -->?= Message-ID: <<!-- TMPL_VAR MSGID -->> <!-- TMPL_IF NAME="DATE" -->Date: <!-- TMPL_VAR DATE --><!-- /TMPL_IF + --> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------<TMPL_VAR BOUNDARY>" Content-Language: ru This is a multi-part message in MIME format. --------------<TMPL_VAR BOUNDARY> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit <TMPL_VAR TEXT> -- signature <TMPL_IF ATTACHMENTS> <TMPL_LOOP ATTACHMENTS> --------------<TMPL_VAR BOUNDARY> Content-Type: <TMPL_VAR FILETYPE>; name="<TMPL_VAR FILENAME>" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="<TMPL_VAR FILENAME>" <TMPL_VAR FILEBASE64> </TMPL_LOOP> </TMPL_IF> --------------<TMPL_VAR BOUNDARY>--

Email code:

my $email_params = { to => $email, from => 'robot@domain.ru', subject => encode_base64('Subject',''), text => 'Mail text', boundary => encode_base64($email,''), date => email_date(time);, msgid => encode_base64($email.$date,'').'@domain.ru', }; foreach my $d (sort keys %{$email_docs} ) { push @{ $email_params->{attachments}}, { FILEBASE64 => encode_base64($d->pdf), # binary FILENAME => $d->filename_pdf, FILETYPE => "application/pdf", } } my $tpl = new HTML::Template(filename => $template); $tpl->param($email_params); open(my $MAIL, "|/usr/local/bin/sudo /usr/sbin/sendmail -t"); print $MAIL $tpl->output; close ($MAIL);

In reply to Re: Formatting a MAil in PERL by alexander_lunev
in thread Formatting a MAil in PERL by jsuresh

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.