Results 1 to 6 of 6

Thread: Winsock -> SMTP

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Sweden
    Posts
    3
    Hi gang!

    I'm in desperate need to get a winsock control in VB6 to conversate with a UNIX SMTP server. If I go with TCP protocol VB keeps bugging me about, "wrong protocol..." errors, but then again, to access a SMTP-server you gotta use TCP and not UDP, right?

    Code example:

    winsock1.connect "<insert SMPT-server here>",25
    winsock1.SendData "HELO <[email protected]>"
    winsock1.SendData "MAIL FROM:<[email protected]>"
    winsock1.SendData "RCPT TO:<[email protected]>"
    winsock1.SendData "DATA"
    winsock1.SendData "<any string you like>"
    winsock1.SendData "."
    winsock1.SendData "QUIT"


    Anyone's got any bright ideas?

    /G

  2. #2
    Guest
    When you call Connect, the two computers don't instantaneously connect. So by using SendData before the computers are connected, an error occurs.

    What you should do is put all your SendDatas in the Winsock's Connect event. This makes sure that Winsock is connected before data gets sent. Also, by sticking the the SendData together like that, Winsock might decide to send it all as one string instead of individual ones. If the server sends acknowledgments to you so you know when you send the next string, you should make use of it. If it doesn't, try some Sleeps inbetween, or use the SendComplete event.

    Sunny


  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Sweden
    Posts
    3
    Tried that to, seems like the computers don't connect at all for some reason...
    I can Telnet the adress and all is perky, but as soon as I try to connect using winsock something seems to be FUBAR:ed.
    This is really getting to me since I can't find the problem, any other solution to send mail from VB without resorting to MAPI or CDONTS?

    /G

  4. #4
    Guest
    Have you tried using simple and only necessary code?

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Winsock1.RemoteHost = "mail.mailserver.com"
        Winsock1.RemotePort = 25
        Winsock1.Connect
    End Sub
    
    Private Sub Command2_Click()
        Winsock1.Close
    End Sub
    
    Private Sub Winsock1_Connect()
        MsgBox "connected"
    End Sub
    Sunny

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Sweden
    Posts
    3
    Yeah, did that to, finally I got the connection, or so I believe since I at least ended up in the Connect event of the Winsock-obj.
    But I'm uncertain that I've got my facts straight, the SendData method sends (surprisingly) data, so a idstring to the SMTP-server would be "HELO <mailaddy>" which it seems to send, then I'd like to see what the server replies, if it replies with a number over 500 something is seriously wrong, otherwise it should be safe to continue.
    But all I get back is a blank (vbcrlf), dunno if I'm doing the wrong thing with GetData strResult, vbString???

    God, somedays I just wish I hadn't got out of bed...

    /G

  6. #6
    Guest
    Well to check if the string was sent, just see if the SendComplete event fires.

    Perhaps it would be easier to debug if you posted you receiving code.

    Just an overview, the GetData method should be in the DataArrival event (ie, when you receive data, you get the data into a variable). The variable which GetData passes data into must be a string, otherwise all you get is ?s in your string. Also, I don't know if the vbString in

    Code:
    Winsock1.GetData strResult, vbString
    is really necessary. Unless you are absolutely sure that the server returns a string, otherwise just leave it out and use

    Code:
    Winsock1.GetData strResult
    Sunny

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