Announcement

Collapse
No announcement yet.

SMTP and ESMTP (Discussion)

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

  • SMTP and ESMTP (Discussion)

    This thread is for discussion of the posts from Wayne Diamond on SMTP and ESMTP.

    Wayne, thanks for both examples!

    My first question is about the ESMTP_GetAuthTypes() function which you posted. Does that function tell me whether my server supports plain SMTP rather than ESMTP? I assume not all servers allow it, but perhaps you can clarify?
    Last edited by Gary Beene; 5 Aug 2014, 08:04 PM.

  • #2
    Gary, usually it's the same daemon handling both SMTP and ESMTP, though it doesn't have to be the case, and yes you can have either one and not the other, or both.

    When you consider an email client like Outlook for example, when you add an email account there's a checkbox "This email account requires authentication". This isn't checked by default, and if it's not checked then the email client always and only tries to use SMTP -- it only uses ESMTP if you check it and add username & password. It never tries to use both.

    So I guess if you want to test for both, simply send HELO first, and look for the 250 success reply code to verify SMTP is up and well, and then do the same for ESMTP using EHLO (although two connections are required to avoid error "503 You already said HELO") - this test seems to work fine
    Last edited by Wayne Diamond; 5 Aug 2014, 09:51 PM.
    -

    Comment


    • #3
      Hey Wayne,
      With Test_ESMTP, I tried my email server "smtp.airmail.net" at port 587 and got good for SMTP but failed for ESMTP.
      ESMTP: Error=503 Saw Helo/Ehlo already
      But when I use those parameters on ESMTP_GetAuthTypes(), it runs successfully, acknowledging that my server handles PLAIN and LOGIN.

      What might be the issue?

      Also, in ESMTP_GetAuthTypes() and Test_ESMTP(), is a TCP Close TCP needed before each of the Exit Function/Sub statements (or else a common exit that has the statement?).

      I like having the ESMTP_GetAuthTypes() available for testing the server options. Thanks for the posts!

      To ensure getting the TCP Close, I did this with your ESMTP_GetAuthTYpes().
      Code:
      Function ESMTP_GetAuthTypes(sServ As String, ByVal dwPort As Dword) As String
       Local hTCP As Dword, sBuf As String, sLocalHost As String
       hTCP = FreeFile
       Tcp Open Port dwPort At sServ As hTCP
       If Err Then GotoExit
        Tcp Recv hTCP, 4096, sBuf
       If Left$(sBuf, 3) <> "220" Then GoToExit
        Host Name To sLocalHost
       If sLocalHost = "" Then sLocalHost = "email"  '// ensure we have a name to send with the HELO/EHLO line
       Tcp Print hTCP, "EHLO " & sLocalHost    '// EHLO (ESMTP) instead of HELO (SMTP)
       Tcp Recv hTCP, 4096, sBuf
       If Left$(sBuf, 3) <> "250" Then GoToExit
       Function = sBuf
      GoToExit:
        Tcp Close hTCP
      End Function
      Last edited by Gary Beene; 5 Aug 2014, 09:19 PM.

      Comment


      • #4
        Ah ok, I guess your mail server only likes the one (either EHLO or HELO) in the one connection. Why is my mail server so much friendlier than yours? Or maybe its just less secure

        I'll adjust the SMTP/ESMTP test code now, check back in a few mins
        -

        Comment


        • #5
          Wayne,
          Why is my mail server so much friendlier than yours? Or maybe its just less secure
          I totally don't know. Servers are at the wide edge of my knowledge spectrum!

          Comment


          • #6
            Updated - http://www.powerbasic.com/support/pb...ad.php?t=55382

            I'll probably be adding AUTH CRAM-MD5 support today also, as Rod Macia has kindly made a test account on his server which has support for that AUTH type, which would pretty much make my ESMTP demo complete, but I need a bit more sleep first (you know how it is when youre a coder)
            Last edited by Wayne Diamond; 5 Aug 2014, 09:31 PM.
            -

            Comment


            • #7
              Gary, some good TLS stuff here if you want to go that way. (I use Socketools)

              Comment


              • #8
                Thanks, Carlo. I'll go take a look.

                Comment

                Working...
                X