Link to home
Start Free TrialLog in
Avatar of bray007
bray007Flag for United States of America

asked on

perl to add html file as body of email

I am simply trying to us MIME::Lite to add the contents of a pre-existing html file as the body of an email, not an attachment.  I have everything working, regarding the email, but can't figure out how to place the html file as the body of an email.  I can make it work using an attachment, but not in the body text.  
Please let me know how to place the contents of a file into the body content of the email message.
I am using Unix.
#!/usr/bin/perl
use MIME::Lite;
use Net::SMTP;
my $mail_host = '11.111.11.11';
$msg = MIME::Lite->new)
From =>'myemail@home.com';
To =>'myfrom@home.com';
Subject =>'send as html inline';
Type =>'text/html';
Data =>'this is where the contents of the external html should go'
);
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia 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
Avatar of bray007

ASKER

Perfect, it worked.  The only edit is an additional ) was removed from your example.  Working sample in the code snippet.
thanks a bunch!
#!/usr/bin/perl
use MIME::Lite;
use Net::SMTP;
# Open and read file contents
open(INFILE,"/path/to/filename.html") or die "Cannot open file $!";
my @filecontents = <INFILE>;
close(INFILE);
# Send email
my $mail_host = '11.111.11.11';
my $msg = MIME::Lite->new(
From =>'myemail@home.com',
To =>'myfrom@home.com',
Subject =>'send as html inline',
Type =>'text/html',
Data => join("",@filecontents);
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

Open in new window