PDA

Click to See Complete Forum and Search --> : Winsock -> SMTP


gollof
Oct 8th, 2000, 08:11 AM
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 <someone@somewhere.com>"
winsock1.SendData "MAIL FROM:<someotherdude@somewhere.com>"
winsock1.SendData "RCPT TO:<you@anywhere.com>"
winsock1.SendData "DATA"
winsock1.SendData "<any string you like>"
winsock1.SendData "."
winsock1.SendData "QUIT"


Anyone's got any bright ideas?

/G

Oct 9th, 2000, 12:48 AM
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

gollof
Oct 9th, 2000, 01:51 AM
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

Oct 9th, 2000, 02:03 AM
Have you tried using simple and only necessary 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

gollof
Oct 9th, 2000, 02:34 AM
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

Oct 9th, 2000, 06:20 AM
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


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


Winsock1.GetData strResult


Sunny