Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Formatting a MAil in PERL

by jsuresh (Acolyte)
on May 28, 2018 at 11:12 UTC ( [id://1215308]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Team,

I'm using perl to take a report and then it will automatically send it as a mail to the users. How can I format the mail in perls? like I want to send using the below format.

Hi All

PLease find the report.

Thanks

AS Team

My current code to send mail is

system "echo $BODY | /usr/local/bin/email -f $MAIL_FROM -n \"RemedyADM\" -s \"Daily and Enhancement Report - HelpDesk Tickets\" -a '/tmp/Daily&Enhancement_Report.zip' -cc $CC $MAIL_TO"

Thanks

Replies are listed 'Best First'.
Re: Formatting a MAil in PERL
by Corion (Patriarch) on May 28, 2018 at 11:16 UTC

    There are a lot of Mail and Email modules.

    Personally, I still like to use MIME::Lite, which has good ways to add text and files to a mail. But there also is Email::Stuffer.

Re: Formatting a MAil in PERL
by marto (Cardinal) on May 28, 2018 at 11:42 UTC

    Ugg, Remedy, it is awful, it does however have the ability to create reports, schedule them and send the results by email. For a perl solution I use MIME::Lite without any problems.

Re: Formatting a MAil in PERL
by rnewsham (Curate) on May 28, 2018 at 11:26 UTC

    Take a look at Task::Kensho it has some suggestions for good email modules

Re: Formatting a MAil in PERL
by alexander_lunev (Pilgrim) on May 28, 2018 at 18:16 UTC

    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);
Re: Formatting a MAil in PERL
by Anonymous Monk on May 28, 2018 at 16:09 UTC
    The same "template" modules that are often used to format web-pages can also be used to format e-mail content, and many of the previously-mentioned mail packages support this notion directly, so that your Perl programming does not have to be changed if every time the e-mails do.
      Design your application from the very start so that content editors can devise new e-mails and change their content just by editing template files, which you read from a designated location separate from your program. Your software "renders the template" to produce the content that is then e-mailed. It generates a list of values which the editors can use in the templates.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found