I wrote a script to send email through our Exchange server. It can send to anyone within the company ([EMAIL PROTECTED]), but that same script won't send to other email addresses (like [EMAIL PROTECTED]).
A nearly identical ASP mailer script can send email anywhere. Both code portions are included here. Any clues? 'Cuz Ahm stumped.
---Perl below---
use IO::Socket qw (:DEFAULT :crlf);
$form{'email_server'}='ip.of.email.server';
$form{'email_from_address'}='[EMAIL PROTECTED]';
@email_to_addresses=('[EMAIL PROTECTED]','[EMAIL PROTECTED]');
$form{'email_subject'}='Subject';
$form{'email_from_name'}='firstname lastname';
$form{'email_to_name'}='firstname lastname';
$form{'email_cc_address'}="doesn't work";
$form{'email_bcc_address'}="doesn't work";
$message='Text of message. <b>Cool</b> stuff.';
print "<b>Attempting to open $form{'email_server'}, port 25</b><br>\n";
$sock=new IO::Socket::INET (
PeerAddr => $form{'email_server'},
PeerPort => '25',
Proto => 'tcp',
);
if (!$sock) {
print "Unable to connect to email server: $!<br>\n";
exit;
}
&r($sock);
# email message
&sr($sock, "HELO company.com$CRLF");
if ($form{'email_from_address'}) { &sr($sock,"MAIL FROM:$form{'email_from_address'} $CRLF"); }
foreach $email_to_address (@email_to_addresses) {
&sr($sock, "RCPT TO:$email_to_address $CRLF");
}
&sr($sock, "DATA$CRLF");
&s($sock, "Content-type:text/html$CRLF");
if ($form{'email_subject'}) { &s($sock, "Subject:$form{'email_subject'}$CRLF"); }
if ($form{'email_from_name'}) { &s($sock, "From:$form{'email_from_name'}$CRLF"); }
if ($form{'email_to_name'}) { &s($sock, "To:$form{'email_to_name'}$CRLF"); }
if ($form{'email_cc_address'}) { &s($sock, "CC:$form{'email_cc_address'}$CRLF"); }
if ($form{'email_bcc_address'}) { &s($sock, "BCC:$form{'email_bcc_address'}$CRLF"); }
&s($sock, "$CRLF");
if ($message) { &s_message($sock, $message); }
&sr($sock, "$CRLF.$CRLF");
&sr($sock, "QUIT$CRLF");
print "<p>Form mailed.<br>\n";
exit;
# send only
sub s {
local($sock)=shift();
local($msg)=shift();
print $sock $msg;
$msg =~ s/\r\n//g;
print "<code>Sent><b>$msg</b></code><br>\n";
}
# send message. same as &s, but it doesn't show the message content.
sub s_message {
local($sock)=shift();
local($msg)=shift();
print $sock $msg;
$msg =~ s/\r\n//g;
print "<code>Sent><b>[message content]</b></code><br>\n";
}
# send and recieve reply
sub sr {
local($sock)=shift();
local($msg)=shift();
local($back);
&s($sock,$msg);
&r($sock);
}
# recieve only
sub r {
local($sock)=shift();
local($back);
recv ($sock, $back, 127,0);
$back =~ s/</</g;
$back =~ s/>/>/g;
$back =~ s/\r\n//g;
print "<code>Resp>$back</code><br>\n";
}
---Perl above---
---ASP below---
<%
set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost ="IP.of.email.server"
Mailer.FromName ="Firstname Lastname"
Mailer.FromAddress = "[EMAIL PROTECTED]"
Mailer.AddRecipient "", "[EMAIL PROTECTED]"
Mailer.Subject="subject line"
Mailer.BodyText="test message!"
Mailer.ConfirmRead=true
Mailer.ContentType="text/html"
if not Mailer.SendMail then
Response.Write " Mailing Failed....Error is: <br>"
Response.write Mailer.Response
else
Response.write "Message Sent Successful...<br> Thanks"
end if
%>
---ASP above---
