Hi everyone.
After a mountain of trouble, I was able to use winSock control in order to connect to the Gmail smtp server in order to send an Email by VB6 program I've made (such a long sentence!); But there's ONE LAST problem:
the socket doesn't send or get information!
Here's the code:
Code:
If sock.State = sckClosed Then
sock.Protocol = sckTCPProtocol
sock.RemoteHost = "127.0.0.1"
sock.RemotePort = "2301"
sock.Connect
Else
sock.Close
End If
lblStatus.Caption = "Sending"
sock.SendData "helo"
And I receive the following error:
Code:
Run-time error '40006': wrong protocol or connection state for the requested transaction or request.
If I check the Status of the sock control after the Connect method, it DOESN'T equal to sckConnected, which means that the socket doesn't connect! And that's why I receive the error! But I don't know why and I don't know how to solve this. Can somebody help me troubleshoot this??
P.N: the address is localhost, yes, but it's tunneled to the Gmail smtp server so don't worry about that part since the problem is not from there.
I forgot to mention that when I telnet the same address and port through command prompt, it works perfectly fine and I can send the Email. It's through the program that it causes problem. I appreciate any help from you.
You are assuming that the connection happens instantaneously, which it doesn't. You need to code the sock_Connect event (which is triggered once the other end has accepted the connection request) and put your senddata there
OK there's another little problem now.
Here's the code:
Code:
Private Sub sock_Connect()
If sock.State = sckConnected Then
lblStatus.Caption = lblStatus.Caption & Chr(13) & "Sending..."
sock.SendData "helo"
lblStatus.Caption = lblStatus.Caption & Chr(13) & "Email Was Sent Successfully!"
Else
lblStatus.Caption = "Error Connecting to the server!"
End If
End Sub
Code:
Private Sub sock_DataArrival(ByVal bytesTotal As Long)
sock.GetData strData
lblStatus.Caption = lblStatus.Caption & Chr(13) & strData
End Sub
After running this, the text of lblStatus will have "Sending... Email Was Sent Successfully!" and nothing else, but in fact, the server is supposed to return some data, and I was expecting to see that too, which I didn't. Please let me know if I'm doing something wrong! Thanks a lot!
I still have difficulties understanding the received data.
When I try telnet under command prompt, I see the response clearly, but when I try to display them in vb, it's like a hash code! like ???????@?@#?????
I don't know why! And when I try to send the commands anyway, I receive a bunch of these weird responses and Email doesn't get sent.
What should I do?? Should I decode this somehow??
I attached the program, although it doesn't work without another program called STunnel that tunnels a local port to Gmail smtp server. The code should help.
Please help me solve this problem
That's right I can see the responses now! But... I can only read them 2 times, and the second time it gives me 2 responses so a total of 3 responses and then I receive nothing... I wonder why...
First, it gives me the message that it gives you when you connect.
Second, I receive two of the responses at one moment. first one is the response gmail gives you when you send "helo" it's something like "Google smtp at your service"
and second one the response of Gmail to "Auth Login" which is a weird hash code.
these responses are natural and are exactly what I should receive.
But the problems is that I don't receive anymore! It doesn't matter if I change the command, like if I send "helo" 10 times, it still gives me 3 responses...
for some reason the socket doesn't send all of the information (only sends 3 of them...)
and after all, I don't receive the Email...
Do you have any ideas?