This needs to be done in TWO separate connections, as 1) many servers will reply with error "503 You already said HELO/EHLO" if you try both HELO and EHLO in the one connection (although some servers allow it), 2) it's possible for two separate server daemons to be running (one for SMTP, one for ESMTP), rather than just the one handling both, and 3) it's possible that they both may be using different TCP ports.
Code:
#COMPILE EXE FUNCTION Test_MailProtocol (sServ AS STRING, BYVAL dwPort AS DWORD, BYVAL dwESMTP AS DWORD) AS DWORD LOCAL hTCP AS DWORD, sBuf AS STRING, sLocalHost AS STRING hTCP = FREEFILE TCP OPEN PORT dwPort AT sServ AS hTCP IF ERR THEN ? "Error - couldn't connect to " & sServ & ":" & FORMAT$(dwPort): EXIT FUNCTION TCP RECV hTCP, 4096, sBuf IF LEFT$(sBuf, 3) <> "220" THEN ? "Error - connected but didn't receive correct protocol header" TCP CLOSE hTCP: EXIT FUNCTION END IF HOST NAME TO sLocalHost IF sLocalHost = "" THEN sLocalHost = "email" '// ensure we have a name to send with the HELO/EHLO line IF dwESMTP = 1 THEN TCP PRINT hTCP, "EHLO " & sLocalHost '// ESMTP ELSE TCP PRINT hTCP, "HELO " & sLocalHost '// SMTP END IF TCP RECV hTCP, 4096, sBuf TCP CLOSE hTCP IF LEFT$(sBuf, 3) = "250" THEN FUNCTION = 1 ELSE ? "Error msg from server = " & sBuf END IF END FUNCTION FUNCTION PBMAIN () AS LONG IF Test_MailProtocol ("mail.myisp.com", 25, 0) = 1 THEN ? "SMTP success!" ELSE ? "SMTP failed!" IF Test_MailProtocol ("mail.myisp.com", 25, 1) = 1 THEN ? "ESMTP success!" ELSE ? "ESMTP failed!" 'port is usually 25 or 587 #IF %DEF(%PB_CC32) STDOUT "Done, press any key to continue...";: WAITKEY$ #ENDIF END FUNCTION
Leave a comment: