[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

perl to add html file as body of email

Posted on 2009-05-13
2
Medium Priority
?
542 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:bray007
2 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 2000 total points
ID: 24372148
Hi bray007,

try something like ...

lwadwell
#!/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

0
 

Author Comment

by:bray007
ID: 24372179
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

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question