Trouble Configuring Outgoing Mail In Perl Cgi

liunx

Guest
Greetings,<br /><br />I'm using FormHandler.cgi from the CGI/Perl Cookbook to handle forms on my website. When a user enters information, two e-mails are supposed to be sent, one to my business and one to the user to confirm the e-mail. The e-mail to me arrives just fine, but the e-mail to the user does not <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> . sendmail is saying that I am trying to relay (wise of it to notice!), and obviously this is not allowed. <br /><br />Surely there is a way to accomplish this. Any ideas?<br /><br />Thanks! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> <br /><br />pagoda<!--content-->
Can you add the key bits of source code so that we can have a look?<br /><br />My guess is that there is somewhere that you need to let it know you are sending from your domain, and not someone outside of your domain using it as a relay for SPAM.<br /><br />Andy.<!--content-->
Hi AndyB,<br /><br />This is where the my script is failing: <br /><br /> print SMTP "RCPT TO:$address$CRLF";<br /> sysread(SMTP, $_, 1024);<br /> /[^0-9]*(\d\d\d)/;<br /> if ($1 ne '250') { push(@bad_addresses, $name{$address}, $_) }<br /> else { ++$good_addresses }<br /> <br />When the value of $address is equal to:<br /><br /> -An e-mail with my TCH domain in it (i.e. <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->),<br /> Then everything works as expected.<br /><br /> -An e-mail address other than one with [email protected], <br /> then it fail with the following message from sendmail:<br /><br />550-server10.totalchoicehosting.com (askmegraphics.com) [209.51.134.50] is<br />550-currently not permitted to relay through this server. Perhaps you have not<br />550-logged into the pop/imap server in the last 30 minutes or do not have SMTP<br />550 Authentication turned on in your email client.<br /><br />Note: $address is the e-mail address being sent _to_. It apparently does not matter where I claim to be sending _from_ so long as the _to_ is an address in the askmegraphics.com domain.<br /><br />I can reliably reproduce this result by manually telnetting to the sendmail port and talking to sendmail. So I must be confused about how to send mail _out_ via a script. Note- my mail goes out just fine from my POP account. Also- the first thing I do to identify myself to sendmail is the following:<br /><br />HELO askmegraphics.com<br /><br />(I also tried explicitely saying "HELO server10.totalchoicehosting.com").<br /><br />I'm sure this is just a simple misunderstanding on my part. Any ideas?<br /><br />Thanks!<br /><br />PS: I'm using mail.askmegraphics.com to create a socket to the sendmail port.<br /><br />pagoda<!--content-->
Greetings All,<br /><br />Ok, I've made some minimal progress on this:<br /><br />-Using /usr/sbin/sendmail works, even when I send an email to someone outside of my domain (as I am going for).<br /><br />-Attaching to a socket (port 25) from within PERL does not work, using the same "To:" and "From:". (For those interested- a code snippet is at the end of this e-mail.)<br /><br />So- Am I to assume that the exim version of sendmail wraps my messages somehow and allows them to go through, but that doing the same thing directly through a PERL socket is verboten? Looks like it.<br /><br />I'm still hopeful someone will tell me otherwise- mainly because I am lazy <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> and don't want to change all the socket references to /usr/sbin/sendmail reference (not impossible- just a hassle).<br /><br />pagoda<br /><br />In the example:<br />$WEB_SERVER = "askmegraphics.com";<br />$SMTP_SERVER = "mail.askmegraphics";<br /><br />Everything works fine until a "RCPT TO:" is issued to the open socket that is not a "local" address, i.e. not <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->   local($SMTP_SERVER_PORT) = 25;<br />    local($AF_INET) = ($] > 5 ? AF_INET : 2);<br />    local($SOCK_STREAM) = ($] > 5 ? SOCK_STREAM : 1);<br />    local(@bad_addresses) = ();<br />    $, = ', ';<br />    $" = ', ';<br /><br />    # Translate hostnames to corresponding addresses and pack<br /><br />    local($local_address) = (gethostbyname($WEB_SERVER))[4];<br />    local($local_socket_address) = pack('S n a4 x8', $AF_INET, 0, $local_address<br />);<br /><br />    local($server_address) = (gethostbyname($SMTP_SERVER))[4];<br />    local($server_socket_address) = pack('S n a4 x8', $AF_INET, $SMTP_SERVER_PORT, $server_address);<br /><br />    # Translate protocol name to corresponding number<br /><br />    local($protocol) = (getprotobyname('tcp'))[2];<br /><br />    # Make the socket filehandle<br /><br />    if (!socket(SMTP, $AF_INET, $SOCK_STREAM, $protocol)) {<br />        $Error_Message = "Could not make socket filehandle ($!).";<br />        return(1);<br />    }<br /><br />    # Give the socket an address<br /><br />    bind(SMTP, $local_socket_address);<br /><br />    # Connect to the server<br /><br />    if (!(connect(SMTP, $server_socket_address))) {<br />        $Error_Message = "Could not connect to server ($!).";<br />        return(1);<br />    }<br />    # Set the socket to be line buffered<br /><br />    local($old_selected) = select(SMTP);<br />    $| = 1;<br />    select($old_selected);<br /><br />    # Set regex to handle multiple line strings<br /><br />    $* = 1;<br /><br />    # Read first response from server (wait for .75 seconds first)<br /><br />    select(undef, undef, undef, .75);<br />    sysread(SMTP, $_, 1024);<br /><br />    # Initiate a conversation with the server<br /><br />    print SMTP "HELO $WEB_SERVER$CRLF";<br />    sysread(SMTP, $_, 1024);<br />    while (/(^|(\r?\n))[^0-9]*((\d\d\d).*)$/g) { $status = $4; $message = $3}<br />    if ($status != 250) { $Error_Message = $message; return(3) }<!--c2--></div><!--ec2--><!--content-->
 
Top