tags:

views:

312

answers:

3

Hello,

I'm building a application that sends a test message to another email, the program executes without errors, but when I check my email there isn't any new email, take a look at my code:

my $smtpserver = 'smtp.vix.terra.com.br';
my $smtpuser = 'nathanpc';
my $fromemail = '[email protected]';

    my $smtp = Net::SMTP-> new($smtpserver, Timeout => 120);
    $smtp-> mail($smtpuser);
    $smtp-> to('[email protected]');
    $smtp-> data();
    $smtp-> datasend("To: eeepc904\@gmail.com\n");
    $smtp-> datasend("From: nathanpc\@terra.com.br\n");
    $smtp-> datasend("\n");
    $smtp-> datasend("test\n");
    $smtp-> dataend();
    $smtp-> quit;
A: 

I think this should be fine

    use Net::SMTP;                          # includes NET:SMTP Moduls

$mailServer  = "mail.server.com";       # Name of  SMTP Servers.

$nachricht   = "nachricht.txt";         # Message
$absender    = "absender\@hier.com";    # Sender Email Adress.
$betreff     = "Neue Nachricht";        # Subject
$empfaenger  = "empfaenger\@dort.com";  # reciver Email Adress



$smtp = Net::SMTP->new($mailServer);    # Create New  SMTP Objekt.
                                        # Parameter is the  Name of SMTP
                                        # Server.

$smtp->mail($absender);                 

$smtp->to($empfaenger);                 
                                        .

$smtp->data();                          

$smtp->datasend("Subject: $betreff\n");

$smtp->datasend("To: $empfaenger\n");

$smtp->datasend("\n");                  

close MESSAGE;

$smtp->dataend(); 

$smtp->quit;
streetparade
+4  A: 

Just because you didn't get the email doesn't mean the email wasn't sent. I could be that it hasn't been delivered yet, or it was delivered and was filtered, or many other things.

There are many, many things that can go wrong with email.

  • Where's the part of the script with warnings and strict enabled, and you load Net::SMTP? Help yourself with those before running to Stackoverflow.
  • Why don't you check that you were able to connect to the mail server?
  • Why haven't you enabled the Debug option in your call to new?
  • Were there any warnings or error messages?
  • What happens when you try the same SMTP conversation by manually connecting to the server? Post the entire transcript.

There is a lot that you can do to help yourself before asking here, and relying on Stackoverflow for even the most basic questions doesn't give you a chance to develop your own skills.

#!perl

use warnings;
use strict;

use Net::SMTP;

my $smtpserver = 'smtp.vix.terra.com.br';
my $smtpuser   = 'nathanpc';
my $fromemail  = '[email protected]';

my $smtp = Net::SMTP->new($smtpserver, Timeout => 10, Debug => 1);
die "Could not connect to server!\n" unless $smtp;

$smtp->mail($smtpuser);
$smtp->to('[email protected]');
$smtp->data();
$smtp->datasend("To: eeepc904\@gmail.com\n");
$smtp->datasend("From: $fromemail\n");
$smtp->datasend("\n");
$smtp->datasend("test\n");
$smtp->dataend();
$smtp->quit;
brian d foy
adapting your code to my email coordiates worked .. (my $smptuser is a fully qualified name, though)
lexu
A: 

Just sniff the traffic to see if there is any SMTP traffic (default port is 25). If you see there is and it corresponds to what you sent (with no errors), you are fine as far as your code is concerned. Your code can't be responsible for what happens after it has successfully been sent (250 Ok: queued...).

Murali VP
It's a remote server, remember that I'm not the owner.
Nathan Campos