Avatar of neotide1976
neotide1976
 asked on

Automated Perl email with generated date in subject

Hello,

I'm trying to generate a daily automated HTML email using Perl and MIME::Lite.  I have most of what I want working coming to Outlook 2007 clients although I cannot for the life of me get the date to work since moving from text to HTML.  The date should be generated behind the subject.  I'm a Perl noob so any guidance would be greatly appreciated!
#!/usr/bin/perl -w
use strict;
use MIME::Lite;
 
# SendTo email id
my $email = 'user@place.com';
 
# Date
my $date = 'date';
 
# create a new MIME Lite based email
my $msg = MIME::Lite->new
(
        Subject => $date,
        From    => 'group@place.com',
        To      => $email,
        Type    => 'text/html',
        Data    => '<html>
                        <body lang=EN-US link=blue vlink=purple>
                        <p><b>-Stuff I am working on:</b></p>
                        <p><b>-Stuff I want looked over:</b></p>
                        </body>
                    </html>'
);
 
$msg->send;

Open in new window

Perl

Avatar of undefined
Last Comment
Adam314

8/22/2022 - Mon
kukno

you need backticks `` for the definiton of $date, if you want to run the external command date and assign $date the output of that command.

e.g.


# Date
my $date = `date`;

Open in new window

kukno

or with builtin function:


my $date=localtime(time);

Open in new window

neotide1976

ASKER
That worked great!  Now when I add the rest of the subject before it though I get errors when trying to run the script.

        Subject => 'Daily Email Report'$date,
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
kukno

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
neotide1976

ASKER
Thanks for your help.  This worked a treat and saved me from pulling the rest of my hair out.  
Adam314

Or use double-quote interpolation:

Subject => "Daily Email Report: $date",

Open in new window