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

Got a strange one. I am trying to send mail to clients when their radio station goes down. It works when the email is within the SMTP server domain but not externally. So if my SMTP server is collins.com and my email is chris@collins.com and I set the TO: field to joe@collins.com everything works fine. If the TO: filed is joe@comcast.net nothing ever gets through. Any bright Ideas?
sub MailSmtp { my $settings = shift(@_); my $stationNumber = shift(@_); my $from = $settings->{fromEmail}; my $reply = $settings->{replyEmail}; my @to = split(/,/,$settings->{emailGroup}); my $subject; my $user = $settings->{user}; my $pass = $settings->{pass}; my $port; if (exists $settings->{port}) { $port = $settings->{port}; }else{ $port = 25; } my $status = $settings->{ports}->{$stationNumber}->{status}; my $relay = $settings->{smtp}; my $smtp; $subject = $settings->{ports}->{$stationNumber}->{id}; $subject = $subject . " is " . $status; my $message = $settings->{message}; $smtp = Net::SMTP->new($relay,Port => $port,Debug => 0,) ; if (!$smtp) { print "\t--[ Could not connect to the email server\n"; return; } $smtp->auth ( $user, $pass); $smtp->mail($from); # use the sender's address here $smtp->recipient($me); # recipient's address $smtp->data(); # Start the mail # Send the header. for $to (@to) { $smtp->datasend("To: $to\n"); } $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("Content-type: text/plain\n\n"); # Send the body. $smtp->datasend("$message\n"); $smtp->datasend(" "); my $res = $smtp->dataend(); $smtp->quit; # Close the SMTP connection print "Email was ", $res ? '' : 'un', "successful.\n"; return; }

Replies are listed 'Best First'.
Re: Sending email only goes to the local domain ??
by merlyn (Sage) on Jun 27, 2007 at 21:13 UTC
    What are the error messages? What do the logs look like on $relay's mail transfer software? Is your incoming IP address permitted to send to anywhere by $relay? (Note: this would not be the default, as it means the system is an open-mail-relay, forbidden by network standards.)
      No errors if the $to starts with a local user email. Can not get the $relay logs. So you are saying even though I own the domain it will not relay?
        Can not get the $relay logs.
        Start there. Stop asking us. You need to talk to the sysadmin of the relay box, if it isn't you. If they have questions, they can ask us.
        A reply falls below the community's threshold of quality. You may see it by logging in.