Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail HTML file as mail content using Mail::Sender 1

Status
Not open for further replies.

ljsmith91

Programmer
Joined
May 28, 2003
Messages
305
Location
US
I create an html report file with a perl script. I now want to use Mail::Sender to email the file to several users. However, I do not want to send the file as an attachment. I want the html file to be the content of the mail message. I am not quite sure of how to do this. Below is what I have so far. I am thinking I need to pass the file to the "msg" parameneter of sender::MailFile instead of "file" parameter but I am just not sure as I cannot get anything with a file to work at this time. Sending a simple message works fine, just not sending a file. Can you point me in the right direction ? Thanks.

Code:
$my_html_report = "\home\reports\my_html_report.htm"

my $sender = new Mail::Sender;
   $sender->MailFile({  {to => "$email",	
	from => 'me_testing',
	SMTP => 'mail.mybusiness.com',
       	replyto => 'me_please',
	file => "$my_html_report",
   	subject => "My HTML Report",
        msg => "Emailing \" $my_html_report \"",
   	auth => 'LOGIN', 
   	authid => 'myuserid', 
   	authpwd => 'mypassword', 
   	ctype => "text/html", 
   	encoding => "7bit" });
 
Don't think it's possible to send it as an HTML e-mail using Mail::Sender. Try using MIME::Lite instead.

M. Brooks
 
I believe there is but I am not sure how...maybe passing the file to the Mail::Sender "msg" parameter instead of "file". Has anyone done this before ?
 
At first glance at your post, this line stood out:

Code:
$my_html_report = "\home\reports\my_html_report.htm"

You're using the escape character \ within double quotes, so it's thinking you're using special characters \h (which doesn't exist), \r (carriage return) and \m (doesn't exist)

Escape the \'s or put it into single quotes since single quotes don't need escape char's (unless it's for another single quote)

Try either of the following to replace that line:

Code:
$my_html_report = "\\home\\reports\\my_html_report.htm";

Code:
$my_html_report = '\home\reports\my_html_report.htm';

And at second look, your line was missing a semicolon too. ;-)
 
Yes... thanks ..I neglected to copy the escape charachter into the post...it was a copy paste but I retyped from memory that piece. That is not the issue. Are you saying that this should work as I have it coded...assuming the escape char in place?
 
I haven't personally used Mail::Sender, but your code looks good as far as defining the content-type of the message.

The "file" attribute is strictly for the attachments. Setting "msg" to a file path wouldn't automatically open the file for you, it would set the message to actually be the string of the file's path.

You can open an HTML file using Perl's open() call
Code:
open (HTML, "$my_html_report");
my @html = <HTML>;
close (HTML);
chomp @html; # removes newlines from each line

# turn the array of lines from the file
# into a single scalar
my $code = join ("\n", @html);

And then you would set "msg" to be the value of "$code", try that. :-)
 
That looks promising. I guess I just thought there was a direct way through the Mail::Sender module. I would think there would be but maybe not.

I will give your logic a try. Thanks so much.
 
In all truth there's not a whole lot of Perl modules which open files for you (and take file paths as their options). Most of them out there expect scalars, arrays and hashes, not file paths (some of them like file handles, but not paths).

So knowing how to open files is always a handy thing. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top