Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2005, 12:22 PM   PM User | #1
NanakiXIII
Regular Coder

 
Join Date: Dec 2003
Posts: 100
Thanks: 1
Thanked 0 Times in 0 Posts
NanakiXIII is an unknown quantity at this point
Net::SMTP - I can't get it right

I'm trying to have a Perl script send an e-mail through an SMTP server, but the e-mail isn't coming out the way it's supposed to. I either get no data in the mail (no sender, etc.), or messed up data. I've also been unable to get ANY e-mail body.
Just a note, I don't know Perl. I've read through the basics but I've never created anything in Perl before. I'm just trying to follow tutorials with this script.

Code:
#!/usr/local/bin/perl -w

use Net::SMTP;

$smtp = Net::SMTP->new('127.0.0.1',Hello => 'Perl');

$smtp->mail("nanakixiii\@ja.nl");
$smtp->to("nanakiiiix\@gmail.com");

$smtp->data;

$smtp->datasend("From: me\@example.com");
$smtp->datasend("To: to\@domain.com");
$smtp->datasend("Subject: This is a test");
$smtp->datasend("\n");

$smtp->datasend("blahblah");
$smtp->dataend;

$smtp->quit;
The above script gets me this header:

Code:
From: @ example. comto <me>
Reply-To: "@ example. comto" <me>, "@ domain. comsubject" <to>, Thisisatest
Date: Sat, 26 Feb 2005 04:19:32 -0800 (PST)
And no body.

Any help would be appreciated.
NanakiXIII is offline   Reply With Quote
Old 02-26-2005, 11:23 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Is there any particular reason why you're using "use Net::SMTP;"?

Are you able to try a script that is more standard like:

===============================================

#!/usr/local/bin/perl

$mailprogram = "/usr/sbin/sendmail";

#
# The webpage where they should be sent after they
# submit the form. Like a thankyou page.

$success = "http://www.mysite.com/thankyou.html";

#######################################

$myemail = "nanakixiii\@ja.nl";
$email = "nanakixiii\@ja.nl";

##########################################
# Send the E-mail

open (MAIL, "|$mailprogram -t") or die "Can't fork sendmail.\n";
print MAIL "To: $myemail\n";
print MAIL "From: $email\n";
print MAIL "Subject: This is an email test.\n";
print MAIL "\n\n";
print MAIL "Blah Blah Blah\n";
print MAIL "Blah Blah Blah\n";
print MAIL "\n";
print MAIL "=====================================================\n";
close(MAIL);

##############################################
# Go To the Success Page

print "Location: $success\n\n";
mlseim is offline   Reply With Quote
Old 02-27-2005, 10:50 AM   PM User | #3
NanakiXIII
Regular Coder

 
Join Date: Dec 2003
Posts: 100
Thanks: 1
Thanked 0 Times in 0 Posts
NanakiXIII is an unknown quantity at this point
I used that because that is what the first tutorial I found suggested. Why? Is there something wrong with Net::SMTP?

I can try sendmail, but I'd still like to know what I did wrong.
NanakiXIII is offline   Reply With Quote
Old 02-27-2005, 04:19 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I've never used "use Net::SMTP;"

someone else might be able to answer.
mlseim is offline   Reply With Quote
Old 02-27-2005, 05:24 PM   PM User | #5
NanakiXIII
Regular Coder

 
Join Date: Dec 2003
Posts: 100
Thanks: 1
Thanked 0 Times in 0 Posts
NanakiXIII is an unknown quantity at this point
I've figured it out. There were supposed to be \n at the end of the lines. I think. Thanks for your help.
NanakiXIII is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:36 AM.


Advertisement
Log in to turn off these ads.