PDA

View Full Version : Net::SMTP - I can't get it right


NanakiXIII
02-26-2005, 01:22 PM
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.


#!/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:


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.

mlseim
02-27-2005, 12:23 AM
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";

NanakiXIII
02-27-2005, 11:50 AM
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.

mlseim
02-27-2005, 05:19 PM
I've never used "use Net::SMTP;"

someone else might be able to answer.

NanakiXIII
02-27-2005, 06:24 PM
I've figured it out. There were supposed to be \n at the end of the lines. I think. Thanks for your help.