Link to home
Start Free TrialLog in
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

Avatar of kukno
kukno
Flag of Germany image

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

or with builtin function:


my $date=localtime(time);

Open in new window

Avatar of neotide1976
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,
ASKER CERTIFIED SOLUTION
Avatar of kukno
kukno
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help.  This worked a treat and saved me from pulling the rest of my hair out.  
Or use double-quote interpolation:

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

Open in new window