User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 456,600 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,443 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1356 | Replies: 1
Reply
Join Date: Aug 2006
Posts: 999
Reputation: EnderX is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
EnderX EnderX is offline Offline
Posting Shark

Question regarding Perl-language mailing script.

  #1  
Sep 10th, 2007
I am trying to program a work-related report system. The reports are generated in php, and I have been requested to have the results sent via email to the individual who needs to review them. (That is, one person generates the reports to look at via an external program, but another person also needs to review them and gets the results in email.)

I found a mailing script we use for something else, and thought I'd managed to modify it for my purposes, but I keep running into a rather strange problem. I'm trying to send an html message to the user's inbox; instead of being the body of the email, the message is being added as an attachment. The original program I modified was designed to send a message and a file; I thought I'd gotten rid of the file-sending portion, but apparently I am incorrect in this.

The code below is a copy of the script I'm using:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Net::SMTP;
use MIME::Lite;


my $from_address = '******@*******.com';
my $to_address = '******@*******.com';
my $mail_host = 'mail.hiwaay.net';
my $msg;

        print "Sending email from $from_address\nto $to_address via $mail_host\n\n";

        my $subject = 'Test Report';
        my $message_body = '<TABLE BORDER=2 RULES=2 GROUPS WIDTH=90%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION><TR><TD ALIGN=RIGHT>Company Totals</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total $</TD></TR></TBODY></TABLE>';

        $msg = MIME::Lite->new (
                From => $from_address,
                To => $to_address,
                Subject => $subject,
                Type => 'text/html',
                Data => $message_body
                 ) or die "$!\n";

        MIME::Lite->send('smtp', $mail_host, Timeout=>60);
        $msg->send;

Can anyone see what I've done wrong in here, that it keeps sending the message as an attachement instead of as the email body?

Please note: the email addresses aren't listed correctly here. I starred them out since I'm testing on my own work email and want to leave as few instances of that out on the web to become spambait as possible. The actual addresses are valid.
Last edited by EnderX : Sep 10th, 2007 at 2:29 pm.
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."

Kumquat.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Question regarding Perl-language mailing script.

  #2  
Sep 12th, 2007
Originally Posted by EnderX View Post
I am trying to program a work-related report system. The reports are generated in php, and I have been requested to have the results sent via email to the individual who needs to review them. (That is, one person generates the reports to look at via an external program, but another person also needs to review them and gets the results in email.)

I found a mailing script we use for something else, and thought I'd managed to modify it for my purposes, but I keep running into a rather strange problem. I'm trying to send an html message to the user's inbox; instead of being the body of the email, the message is being added as an attachment. The original program I modified was designed to send a message and a file; I thought I'd gotten rid of the file-sending portion, but apparently I am incorrect in this.

The code below is a copy of the script I'm using:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Net::SMTP;
use MIME::Lite;


my $from_address = '******@*******.com';
my $to_address = '******@*******.com';
my $mail_host = 'mail.hiwaay.net';
my $msg;

        print "Sending email from $from_address\nto $to_address via $mail_host\n\n";

        my $subject = 'Test Report';
        my $message_body = '<TABLE BORDER=2 RULES=2 GROUPS WIDTH=90%><CAPTION><B><FONT SIZE=+1></FONT></B></CAPTION><TR><TD ALIGN=RIGHT>Company Totals</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Pest $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Term $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Vent $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Other $</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total #</TD><TD ALIGN=RIGHT FONT SIZE=-2>Total $</TD></TR></TBODY></TABLE>';

        $msg = MIME::Lite->new (
                From => $from_address,
                To => $to_address,
                Subject => $subject,
                Type => 'text/html',
                Data => $message_body
                 ) or die "$!\n";

        MIME::Lite->send('smtp', $mail_host, Timeout=>60);
        $msg->send;

Can anyone see what I've done wrong in here, that it keeps sending the message as an attachement instead of as the email body?

Please note: the email addresses aren't listed correctly here. I starred them out since I'm testing on my own work email and want to leave as few instances of that out on the web to become spambait as possible. The actual addresses are valid.


I use Net::SMTP to send HTML email for a client, but you don't seem to, even though you 'use' it. Also, you don't seem to have a legal HTML document, but just a table. You need to wrap everything in HTML tags, as if it were a stand-alone HTML document.

Try a simple test of sending HTML email to yourself using something like this:

my $smtp = Net::SMTP->new('localhost');	
$smtp->data();
my $msgformat = "text/html";
$smtp->datasend("Content-Type: $msgformat\n");
$smtp->datasend("To: $e\n");
$smtp->datasend("From: $From\n");
$smtp->datasend("Subject: $Subject\n\n");
$smtp->datasend("$HeaderHTML");
$smtp->datasend("$ContentHTML");
$smtp->datasend("$FooterHTML");
$smtp->dataend();
$smtp->quit();

where you have defined the variables elsewhere.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 7:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC