bengmau has asked for the wisdom of the Perl Monks concerning the following question:

trying to send an e-mail using a specific port. I read up on this on a previous discussion but my e-mail is not getting to my inbox.. if someone can check my code and tell me if I have something quirky somewhere I can't see it.
my $from = "$cfg->{mail}->{'from'}"; my $to = "$cfg->{mail}->{'to'}"; my $host = $cfg->{mail}->{smtp_host}; INFO("sending message to $to via $host"); ## My NET::SMTP invocation my $port = $cfg->{mail}->{smtp_port}; my $s = Net::SMTP->new( $host, Port => $port ); print $s->banner(), "\n"; $s->to($to); $s->mail($from); $s->data(); $s->datasend("To: $to\n"); $s->datasend("\n"); $s->datasend("$message \n" ); $s->datasend( "\n" ); $s->dataend(); $s->quit();
from and to scalars address are in the format blah@blah.com when I telnet manually and do the same as what the perl script does it sends the e-mail. so I know it's something about the coding

Replies are listed 'Best First'.
Re: NET::SMTP help
by NetWallah (Canon) on Mar 10, 2005 at 05:50 UTC
    Try turning on Debug.
    my $s = Net::SMTP->new( $host, Port => $port , Debug => 1);

        ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

      Looks like I set the $s->to before the $s-mail. THat was it. thanks for the debugger flag suggestion "newman you are wise", Kramer
Re: NET::SMTP help
by chas (Priest) on Mar 10, 2005 at 05:32 UTC
    Did you try it without specifying a port option? (I believe the default is 25.)
    It is hard to comment much without knowing exactly what the $cfg->{}->{} values are.
    (Update-comment: You escaped the @ in "blah@blah.com", didn't you?)
    chas
      well the thing is I have to specify a port because my smtp port is not 25 which is why I'm using net:smtp instead of email::send I didn't think I had to escape the @ in blah@blah.com since I'm reading in a config file which populates the $cfg->{}->{} When I'm debugging the program the program variables appear correct. I'll try escaping the e-mail address nonetheless and see what happens
        It depends..."blah@blah.com" is likely to be problematical due to interpolation of @blah.
        chas
Re: NET::SMTP help
by Tanktalus (Canon) on Mar 10, 2005 at 14:17 UTC

    Do you have access to the SMTP server logs? If not, try to get access. It likely will tell you the problem. My bet is that you're not supplying enough header information. For example, there's no 'From:' header. I know you're sending it via $s->mail($from), but some SMTP servers like to see it in the actual header, too. Further, there's no subject nor date stamp. I'm not sure which ones may be required, but I would suggest that some SMTP servers (or some spam filters) would reject anything without these because either they don't conform to the standard, or because they're hallmarks of spam.

      how do I add the from and subject headers using NET::SMTP. sorry a little new to NET::SMTP. the example is pretty basic.
        $s->to($to); $s->mail($from); $s->data(); $s->datasend("To: $to\n"); ### $s->datasend("From: $from\n"); $s->datasend("Subject: Hi, this looks like SPAM ... but it ain't.\ +n"); $s->datasend('Date: ', scalar(time), "\n"); ### $s->datasend("\n"); $s->datasend("$message \n" ); $s->datasend( "\n" ); $s->dataend(); $s->quit();

        Note the lines I added between the triple-hashmarks.