Results 1 to 5 of 5

Thread: [RESOLVED] SMTP Conversation

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [RESOLVED] SMTP Conversation

    Following on from this thread - http://www.vbforums.com/showthread.php?t=580359 (which follows on from another one..) I am trying to make my own SMTP server and am having a few problems.

    I'm using the TcpClient and TcpListener classes to read/write to the network when a request comes in on port 25. All I'm trying to do at the moment is make it so that my server program can receive SMTP messages from other SMTP servers. I've tested in Telnet - if I connect to my own IP on port 25 and type EHLO, MAIL FROM, RCPT TO, DATA etc then all works as it should and the details I entered are logged by the program (it doesnt do anything about delivering these details/email yet).
    So all looks good... but then when I try and just send an email to my domain from my work account I can see that a connection is made to my program and the string "EHLO workdomain.com " is received by my program - my program responds to the remote SMTP server with "250-mydomain.com Hello" and then a CrLF and then "250-OK". After that point however, my app does not receive anything further at all from the server at work. I'm guessing I am doing something wrong with the data I'm returning when it sends EHLO but can anyone point me in the correct direction?
    I can post code if necessary but I dont know if that will help really

    Thanks
    Chris

    EDIT: Ah, I've just found the cause of one problem... because I was using telnet to test with, it seems that I have made it work only with telnet... In telnet each time I type a key the data is passed to the server, however with a real SMTP server it just sends each entire command in one go. So after altering my server a little I can now get it to respond with the 250-OK which I thought it already was doing.. but it still doesnt work. The remote server just sends EHLO and then thats it nothing more

    EDIT EDIT: Something interesting, at the moment I am ending all of my responses to the remote server with VbLf - if I change this to VbCrLf (which is what I believe it is meant to be according to the SMTP standard) then I get an infinite amount of empty strings sent to my program (or perhaps some other character that just shows as an empty string in intellisense when stepping through the code). Changing it back to just vbLf or ControlChars.Lf makes it go back to just sending EHLO and then nothing else..
    Last edited by chris128; Aug 14th, 2009 at 11:50 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: SMTP Conversation

    Some kind person on the Exchange Server forums told me that the SMTP response has to be CODE MESSAGE rather than CODE-MESSAGE like I am doing (so 250 OK instead of 250-OK) so I will give that a go and see what happens later today
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: SMTP Conversation

    Can you explain the infinite amount of empty strings? Are you sure you are getting empty strings and not something that has a byte value of 0, which translates to an empty string.

    Take this example:

    Code:
           Dim b() As Byte = {65, 65, 0,0,0,0,0,0}
            Dim s As String = System.Text.Encoding.ASCII.GetString(b)
            MessageBox.Show(s)
    I bet this is something similar to what you are seeing, where you have no quote terminator in the watch window.

  4. #4

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: SMTP Conversation

    I'm not sure what it was but its not doing it now since I changed my servers EHLO response from 250-OK to 250 OK . Now it gets a lot further
    The remote server sends EHLO, then MAIL FROM, then RCPT TO, then DATA but then after that it sends RSET and then MAIL FROM again, presumably because something went wrong in the DATA section (which I was kind of expecting because again, I geared that part around the telnet input I was testing with originally).
    So I'll work on the DATA part later tonight and see how it goes Thanks
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: SMTP Conversation

    OK I think I know what was causing the infinite amount of strings or whatever they were - my stupidity (yes, again). When I was responding to the remote server I was using the NetworkStream's WriteLine method as well as appending a vbCrLf to the message, when I should have been using the Write method with a vbCrLf appended (although I'm guessing I could probably just use WriteLine and not manually append anything but whatever it works this way so I'm happy). So now that I have corrected that and made quite a few other alterations, it all works fine

    Of course at the moment its not actually doing anything with the message it receives, just outputting the recipient and message body etc to the screen. So that's the next challenge... but I'm glad I started this little project as I'm learning quite a bit from it. Thanks for your help so far Negative0, I'm sure I'll encounter another problem soon enough and be posting a new thread after I've beaten my head against a wall for a few hours
    I do have one issue actually but its not so much a problem and more just a code style/layout question - here's the thread if you are interested: http://www.vbforums.com/showthread.php?t=580552
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width