PDA

Click to See Complete Forum and Search --> : having problems with winsock prog


Charlezz
Dec 10th, 1999, 05:39 AM
ok, here is my code....
[code]
Private Sub Command1_Click()
Caption = "Sending Message.."
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect """" & txtMailserver & """", 25
End Sub

Private Sub Winsock1_Connect()
Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
"MAIL FROM: <" & txtMailFrom & ">" & vbCrLf & _
"RCPT TO: <" & txTto & ">" & vbCrLf & _
"DATA" & vbCrLf & _
"TO: " & txTto & vbCrLf & _
"FROM: " & txtFrom & vbCrLf & _
"SUBJECT: " & txtSubject & vbCrLf & _
txtmessage & vbCrLf & "." & vbCrLf & _
"QUIT" & vbCrLf
End Sub
Private Sub Winsock1_SendComplete()
Caption = "Send Complete."
End Sub
[\code]
please correct this and send it back. I don't know what is wrong with it.
[code]

oh, it needs these....
txtMailserver (where the user types in the mail server of course)
txtMailFrom(gives the user the choice of entering their real adress or a fake adress)(this is where the user types in an email adress)
txtfrom(this is where the user types in a name, real or fake, no matter)
txtto(email adress of recipitent)
txtsubject(DUH!)
txtmessage(I think you can figure it out)
winsock1(the winsock controll)
command1(the "send email" button)
[\code]

problems.....
no message shows up
will not connect to mail server
I'm not Sure what else....
please help....

deDogs
Dec 10th, 1999, 06:55 AM
Have you built Error Handling routine to find if an error occurred.

sckMain_Error(Number, Description, Scode, Source, HelpFile, HelpContext, CancelDisplay)

deDogs

Yonatan
Dec 10th, 1999, 07:31 AM
Play around with the mail server using Telnet...

This is what I did to test it:

Connect menu -> Remote System...
Host Name: mail.netvision.net.il
Port: 25 (If you want to check for E-Mail, instead of 25 use POP3)
TermType: vt100

HELO Yonatan
Server response: Hello (My IP goes here) , nice to meet you
MAIL FROM: <RZvika@netvision.net.il>
Server response: <RZvika@netvision.net.il>... Sender ok
RCPT TO: <RZvika@netvision.net.il>
Server response: <RZvika@netvision.net.il>... Recipient ok
DATA
Server response: Enter mail, end with "." on a line by itself
TO: RZvika@netvision.net.il
FROM: RZvika@netvision.net.il
SUBJECT: Test message to myself...
Testing... 1, 2, 3... Is this on?
.
Server response: DAA29262 Message accepted for delivery
QUIT
Server response: Closing connection

Telnet MsgBox: Connection to host lost.

After a few seconds I got my message just as I wanted it!

Try it yourself, experiment with it and you'll be able to learn about how the E-Mail system works and how to use it from VB!

Also, the Outlook Express program has an ability to keep track of all the commands it sends to/receives from the mail server and log them in a log file.
Check the Mail CheckBox here:
Tools menu -> Options -> Maintenance -> Troubleshooting -> Mail

Afterwards, send or receive some mail using Outlook Express. When you are done experimenting (try sending an attachment, carbon copies, blind carbon copies, whatever) look for two files on your hard drive: POP3.LOG - all the commands sent to/received from the mail server regarding receiving E-Mail, and SMTP.LOG - all the commands sent to/received from the mail server regarding sending E-Mail.
Don't forget to uncheck the CheckBox, because the two files can get really big!

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69

Frans C
Dec 10th, 1999, 10:44 PM
I tried your code, and after I removed the quotes around the remotehost it worked fine. So I changed:
Winsock1.Connect """" & txtMailserver & """", 25
to
Winsock1.Connect txtMailserver, 25

DiGiTaIErRoR
Dec 11th, 1999, 07:02 PM
Frans C could I see the final code you used?
I've been wondering how to do this actually.
Thanks.

------------------
DiGiTaIErRoR

Frans C
Dec 11th, 1999, 07:59 PM
Sure! But all the credit goes to Charlezz. I just removed some quotes.


Option Explicit

Private Sub Command1_Click()
Caption = "Sending Message.."
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect txtMailserver, 25
End Sub
Private Sub Winsock1_Connect()
Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
"MAIL FROM: <" & txtMailFrom & ">" & vbCrLf & _
"RCPT TO: <" & txtto & ">" & vbCrLf & _
"DATA" & vbCrLf & _
"TO: " & txtto & vbCrLf & _
"FROM: " & txtfrom & vbCrLf & _
"SUBJECT: " & txtsubject & vbCrLf & _
txtmessage & vbCrLf & "." & vbCrLf & _
"QUIT" & vbCrLf
End Sub
Private Sub Winsock1_SendComplete()
Caption = "Send Complete."
End Sub

Frans C
Dec 13th, 1999, 12:16 AM
Try to figure out where it goes wrong. Try adding some
debug.print winsock1.state
line at various points. This way, you can find out if the connection doesn't succeed or the sending gives the problems.
Also try the error event of the winsock control. Further you could try to ping to the remote host, so your sure the address is ok. Maybe your provider doesn't listen to port 25, so you could try a different one (but this may be looking for a needle in a haystack).

This is hard to debug from a distance.
Sorry I couldn't do more.

Charlezz
Dec 13th, 1999, 09:48 AM
That's ok, you've been a gret help, all of you! :) :)

Charlezz
Dec 13th, 1999, 11:49 AM
I dont know why, but it still won't work, i click the button and it just says on the caption "sending message"

visualAd
Dec 14th, 2004, 06:12 AM
The reason it is not working is because you are using the HTML entities &gt; and &lt; when sending the mail use < and > instead. You should also send the data one line at a time and ensure you receive a 200 OK reponse from each line, sometimes the mail server may refuse to send the e-mail.