Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2003
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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";

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I've never used "use Net::SMTP;"

    someone else might be able to answer.

  • #5
    Regular Coder
    Join Date
    Dec 2003
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've figured it out. There were supposed to be \n at the end of the lines. I think. Thanks for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •