Announcement

Collapse
No announcement yet.

Sendmail Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sendmail Problem

    Hi All,

    Had this function ruinning on our web server for more than 8 years now and just now it's not sending emails.

    It seems to fail on the Helo command.

    Here is the output of the function

    Code:
    SendMail
    
    Error  0 
    localhost misterdj
    Buffer RCPT TO error: 504 5.5.2 <misterdj>: Helo command rejected: need fully-qualified hostname
    Mail From [email protected]
    Mail To [email protected]
    Reply 
    MessageType text/html;
    Subject Order Confirmation
    ---- Message ----
    Copy Email<br><br>Order Confirmation<br><br>86.156.44.13<br><br><table border=0 cellspacing=0 cellpadding=4><tr><td align=center><a href=http://www.djsuperstore.co.uk>
    <img src=http://www.djsuperstore.co.uk/logos/djsuperstore.gif border=0><br>www.djsuperstore.co.uk</a></td><td>&nbsp;</td><td><b>DJ Superstore<br>Unit 5, Airborne Industrial Estate,<br>A127 Arterial Road, Leigh On Sea,<br>Essex, SS9 4EX, UK<br>Tel 01702 520020</td></tr></table><br>
    Order Confirmation Number :M-W-15699:<br><br>
    Placed Tuesday 18/11/2008 - 15:45:17</b><br><br>
    <table border=1 cellspacing=0 cellpadding=5 bordercolor=black class=t2bk><tr><td>Customer Number 11120<br>Mr Some Customer</td></tr></table>
    <br>
    Your Order :-<br><br>
    <table border=1 cellspacing=0 cellpadding=3 bgcolor=silver bordercolor=black>
    <tr><td><b>Qty<td><b>Order Code<td colspan=2><b>Description<td align=right><b>Unit Price<td align=right><b>Line Total
    <tr><td>1</td><td>106362<td nowrap>Pioneer</td><td>HDJ1000 Headphones<td align=right nowrap>£ 119.00<td align=right nowrap>£ 119.00
    <tr><td colspan=3 rowspan=2>&nbsp;</td><td colspan=2>Shipping Charge<td align=right nowrap>£ 0.00</td></tr>
    <tr><td colspan=2>Order Total</td><td align=right nowrap>£ 119.00</td></tr>
    </table><br>
    Your order will be despatched as soon as possible.<br><br>Thank you for your order.<br><br>DJ Superstore
    -----------------
    86.156.44.13

    Code:
    FUNCTION SendMail( BYVAL MailFrom AS STRING, BYVAL MailTo AS STRING, BYVAL Reply AS STRING, BYVAL MessageType AS STRING, BYVAL Subject AS STRING, BYVAL Message AS STRING ) AS LONG
    	'
    	LOCAL LocalHost AS STRING
    	LOCAL TL1 AS long
    	LOCAL Buffer AS STRING
    	local TS1 as string
    	' ** Get the local host name
    	HOST ADDR TO hTCP_GL
    	HOST NAME hTCP_GL TO LocalHost
    	' ** Connect to mail server
    	hTCP_GL = FREEFILE
    	TCP OPEN "smtp" AT $MailHost AS hTCP_GL
    	IF ERR THEN
    		Buffer = "Error connecting to mailhost"
    		GOTO SendError
    	ELSE
    		TCP LINE hTCP_GL, Buffer
    		IF LEFT$( Buffer, 3 ) <> "220" THEN
    			GOTO SendError
    		END IF
    	END IF
    	' ** Greet the mailhost
    	TCP PRINT hTCP_GL, "HELO " + localhost
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "250" THEN
    		Buffer = "HELO error: " + Buffer
    		GOTO SendError
    	END IF
    	' ** Tell the mailhost who we are
    	TCP PRINT hTCP_GL, "MAIL FROM: <" + MailFrom + ">"
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "250" THEN
    		Buffer = "MAIL FROM error: " + Buffer
    		GOTO SendError
    	END IF
    	' ** Tell the mailhost who the message is for
    	TCP PRINT hTCP_GL, "RCPT TO: <" + MailTo + ">"
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "250" THEN
    		Buffer = "RCPT TO error: " + Buffer
    		GOTO SendError
    	END IF
    	' ** Send the message
    	TCP PRINT hTCP_GL, "DATA"
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "354" THEN
    		Buffer = "DATA error: " + Buffer
    		GOTO SendError
    	END IF
    	TCP PRINT hTCP_GL, "Content-Type: " + MessageType
    	TCP PRINT hTCP_GL, "From: " + MailFrom
    	TCP PRINT hTCP_GL, "To: " + MailTo
    	IF Reply <> "" THEN
    		 TCP PRINT hTCP_GL, "Reply-To: " + Reply
    		 end if
    	TCP PRINT hTCP_GL, "Subject: " + Subject
    	TCP PRINT hTCP_GL, ""		'end of header
    	' ** Send the message
    	WHILE LEN( Message ) > 0
    		TL1 = INSTR( Message, "ÿ" )		' "ÿ"=chr$(255)
    		IF TL1 = 0 THEN
    			TCP PRINT hTCP_GL, Message;
    			IF MessageType = "text/html;" THEN 
    				TCP PRINT hTCP_GL, "<BR>"
    				end if
    			IF Messagetype = "text/plain;" THEN
    				 TCP PRINT hTCP_GL, ""
    				 end if
    			Message = ""
    		ELSE
    			TCP PRINT hTCP_GL, LEFT$( Message, TL1 - 1 );
    			IF MessageType = "text/html;" THEN
    				 TCP PRINT hTCP_GL, "<BR>"
    				 end if
    			IF Messagetype = "text/plain;" THEN
    				 TCP PRINT hTCP_GL, ""
    				 end if
    			Message = MID$( Message, TL1 + 1 )
    		END IF
    	WEND
    	TCP PRINT hTCP_GL, "."
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "250" THEN
    		GOTO SendError
    	END IF
    	' ** Say goodbye
    	TCP PRINT hTCP_GL, "QUIT"
    	TCP LINE hTCP_GL, Buffer
    	IF LEFT$( Buffer, 3 ) <> "221" THEN
    		Buffer = "QUIT error: " + Buffer
    		GOTO SendError
    	END IF
    	TCP CLOSE hTCP_GL
    	FUNCTION = - 1
    	'  Done
    	EXIT FUNCTION
    SendError :
    	FUNCTION = ERR
    	TCP CLOSE hTCP_GL
    	'
    	#IF %Environ = %Live
    		'
    		ON ERROR RESUME NEXT
    		'
    		TS1 = GetNextRef( $UserFilesDataDir + "Ref\Ref.wmm", "", 0, 9999999, 1 )
    		TL1 = FREEFILE
    		OPEN $UserFilesDataDir + TS1 + ".wmm" FOR OUTPUT AS #TL1
    		'	STD_OUT( "An error has occured. " + STR$( ERR ) + " (error log generated)<br><br>")
    		'	STD_OUT( "<a href=clg.cgi>Please click here to continue</a>")
    		PRINT #TL1, "SendMail" 
    		print #TL1
    		print #TL1, "Error " ERR
    		print #TL1, "localhost "localhost
    		print #TL1, "Buffer " Buffer
                              print #TL1, "Mail From " MailFrom
    		print #TL1, "Mail To "MailTo
    		print #TL1, "Reply " Reply
    		print #TL1, "MessageType " MessageType
    		print #TL1, "Subject " Subject 
    		
    		print #TL1, "---- Message ----"
    		print #TL1, Message
    		print #TL1, "-----------------"
    		PRINT #TL1, ENVIRON$( "REMOTE_ADDR" )
    		CLOSE #TL1
    		'
    END FUNCTION

  • #2
    Wondering if it's a problem on their mail server?

    Just modified the sendmail routine from the downloads area. The program fails just after the print "3" statement and outputs

    Code:
    1
    2
    3
    Error State
    RCPT TO error: 504 5.5.2 <misterdj>: Helo command rejected: need fully-qualified
     hostname
    Code:
    #COMPILE EXE
    #INCLUDE "PBCGI.INC"
    
    '------------------------------------------------------------------------------
    
    FUNCTION PbMain() AS LONG
    
      LOCAL hTcp      AS LONG
      LOCAL params    AS LONG
      LOCAL x         AS LONG
    
      LOCAL buffer    AS STRING
      LOCAL localhost AS STRING
    
      LOCAL mailto    AS STRING
      LOCAL mailfrom  AS STRING
      LOCAL mailhost  AS STRING
      LOCAL subject   AS STRING
      LOCAL email     AS STRING
      LOCAL required  AS STRING
    
      mailto   = "[email protected]"
      mailfrom = "[email protected]"
      mailhost = "smtp.mail.areti.net"
      subject  = "test"
      
    ' ** Connect to mail server
      hTCP = FREEFILE
      TCP OPEN "smtp" AT mailhost AS hTCP
      IF ERR THEN
        Buffer = "Error connecting to mailhost"
        GOTO SendError
      ELSE
        TCP LINE hTCP, Buffer
        IF LEFT$(Buffer, 3) <> "220" THEN
          GOTO SendError
        END IF
      END IF
    
    ' ** Get the local host name
      HOST NAME TO localhost
    
    ' ** Greet the mailhost
      print "1"
      TCP PRINT hTCP, "HELO " + localhost
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "250" THEN
        Buffer = "HELO error: " + Buffer
        GOTO SendError
      END IF
      print "2"
    ' ** Tell the mailhost who we are
      TCP PRINT hTCP, "MAIL FROM: <" & mailfrom & ">"
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "250" THEN
        Buffer = "MAIL FROM error: " + Buffer
        GOTO SendError
      END IF
      print "3"
    ' ** Tell the mailhost who the message is for
      TCP PRINT hTCP, "RCPT TO: <" + mailto + ">"
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "250" THEN
        Buffer = "RCPT TO error: " + Buffer
        GOTO SendError
      END IF
      print "4"
    ' ** Send the message
      TCP PRINT hTCP, "DATA"
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "354" THEN
        Buffer = "DATA error: " + Buffer
        GOTO SendError
      END IF
    
      TCP PRINT hTCP, "From: " & mailfrom
      TCP PRINT hTCP, "To: " & mailto
      TCP PRINT hTCP, "Subject: " & subject
      TCP PRINT hTCP, "X-Mailer: PowerBASIC mailer.exe (www.powerbasic.com)"
      TCP PRINT hTCP, ""
    
      tcp print hTCP, "This is a test email message"
    
    ' ** We're done sending the message
      TCP PRINT hTCP, "."
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "250" THEN
        GOTO SendError
      END IF
    
    ' ** Say goodbye
      TCP PRINT hTCP, "QUIT"
      TCP LINE hTCP, Buffer
      IF LEFT$(Buffer, 3) <> "221" THEN
        Buffer = "QUIT error: " + Buffer
        GOTO SendError
      END IF
    
      TCP CLOSE hTCP
    
    ' ** Redirect the user's browser to the new page
      
    
      FUNCTION = -1
    
    Done:
      EXIT FUNCTION
    
    SendError:
      print "Error State"
      print buffer
      TCP CLOSE hTCP
      waitkey$
      GOTO Done
    
    END FUNCTION

    Comment


    • #3
      Steve,

      Just off the top of my head, you might be trying to connect to a server that is enforcing a reverse look-up on your domain name. If so, you'll need to make sure that you have a reverse DNS entry for your email server that matches exactly to the IP address. Many ISPs that provide static addresses and do your DNS for you fail to create a reverse IP entry for your domain so it points back to their domain name instead.

      Another thing to look at:
      localhost misterdj
      Buffer RCPT TO error: 504 5.5.2 <misterdj>: Helo command rejected: need fully-qualified
      The domain name you are passing in the Helo statement is 'misterdj'. The server is saying that it wants a real domain name. ie: mail.misterdj.com

      Clearly this is an anti-spam attempt by the receiving server, so you're going to have to change your headers to match what that server is looking for.
      Software makes Hardware Happen

      Comment


      • #4
        Thanks Joe,

        Been speaking to the ISP and they did make changes.

        Looks like I need to be using relay.mail.areti.net instead as smtp.mail.areti.net requires a username and password.

        Just out of interest, whats the syntax for defining this in the function?

        Comment


        • #5
          Steve
          Little different answer for you than Joe's which would more properly apply if you are sending direct to many different mail servers, but as I read your code you don't have your own mail server but are just sending outgoing emails via your ISP's mail servers.
          In that case it sounds like they have simply split the mail load between primarily incoming and outgoing mail (very common), so simply change to the new outgoing server name they have given.
          Whilst the word "relay" in the name is unusual, I would imagine it is locked down from being an open relay and only accepts outgoing mail IP addresses that it knows belong to the ISP.
          As for the qualified domain name and reverse lookup, these then no longer apply to you as the final receiving mail server will be verifying that information about your ISP's server names not yours.
          John

          Comment


          • #6
            Thanks John, after checking you are correct. The mail server is only available to my ISP's customers in the datacentre.

            I still have an issue when sending emails close together in time. The first one goes out ok but the second does not.

            I don't have the time yet to fully work out why.

            Comment


            • #7
              That's another common anti-spam measure (in the smtp server). In the same league as an isp limiting the number of people in the To:/CC:/BCC: fields.

              The best way I've found is to place a 2-5 sec delay (random) between each outgoing email.

              - or -

              get your own server

              - or -

              use a service like goldbar.net, aweber (personally, I like goldbar better), or listbox.com (I've used their POBOX email service since 96 and LOVE it).

              Hope this helps.

              JS
              John,
              --------------------------------
              John Strasser
              Phone: 480 - 273 - 8798

              Comment

              Working...
              X