Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Formatting a MAil in PERL

by alexander_lunev (Pilgrim)
on May 28, 2018 at 18:16 UTC ( [id://1215338]=note: print w/replies, xml ) Need Help??


in reply to Formatting a MAil in PERL

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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1215338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-25 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found