Solved

perl to add html file as body of email

Posted on 2009-05-13
2
492 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now