Solved

perl to add html file as body of email

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now