Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Templating emails

by Bod (Parson)
on Jul 02, 2021 at 16:40 UTC ( [id://11134591]=perlquestion: print w/replies, xml ) Need Help??

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

Ever since asking To Framework or not to Framework, I have used Template for everything that needs anything more than a minute amount of output. Web pages, reports, forms, etc. Using Template has made development much quicker and maintenance much simpler.

But the one place I don't use a templating system is email.
Well I do - of sorts. I have an HTML file that my script reads in, substitutes some bits of text before passing it to MIME::Lite to be sent out. This works but does mean having the template processing code embedded in my script or me reinventing it in a module.

So, what do you recommend to a user of Template for email templating?

I have looked at MIME::Lite::TT::HTML but notice that it hasn't been updated for 14 years. There is also Email::Template.

Do you have any recommendations for these or another templating module for emails?

Replies are listed 'Best First'.
Re: Templating emails
by Fletch (Bishop) on Jul 02, 2021 at 17:01 UTC

    Erm . . . Template. It'll work just fine for emails with MIME::Lite as your current mechanism (or probably pretty much any current email sending module).

    If you've got some specific issues you've come across that lead you to think you can't use it it might help to enumerate on those.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      If you've got some specific issues you've come across that lead you to think you can't use it it might help to enumerate on those

      I'd missed that Template could output to somewhere other than STDOUT! Having gone back and looked at the documentation, I see what I had missed!

      Is something like this the right way to do it (untested):

      my $mail; $template->process('mail.tt', $vars, \$mail) || die "Template problem! +"; my $mime = MIME::Lite->new( From => 'abc@xyz.com', To => 'you@yours.com', Subject => 'Test', Type => 'text/html', Date => $mail, ); $mime->send;
      Or does it need something more than that - other than error checking and validation of course.

        ITYM Data not Date, but yup that's heading the right direction. For some reason I tend to initialize a target buffer with an empty string my $mail = q{} (which may be cargo culting or just strange ingrained habit), and I'd include $template->error in the message so you've got more to go on.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Re: Templating emails
by Perlbotics (Archbishop) on Jul 02, 2021 at 17:37 UTC

    Not sure if it fits your requirements, but I am pretty happy using Mojo::Template and Email::Stuffer to generate rather complex email reports at $work.

    Greates PITA was fiddeling around with Outlooks HTML capabilities and to set proper headers so our company's spam filters and AIP did not complain.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found