ash11001 Level: Trainee
 Registered: 07-04-2007 Posts: 1
|
Sending an email with Winsock
Hi all, I have some code I've written that should log into a specified SMTP server on port 25 and send an email, but it won't work, and I can't seem to figure out why. Any help is much appreciated.
Private Sub cmdSend_Click()
'grab everything after the "@" for the HELO command
Dim sym As Integer 'for holding the position of the "@" SYMbol
Dim total As Integer
Dim calc As Integer
Dim smtp As String
sym = InStr(txtSMTP.Text, "@")
total = Len(txtSMTP.Text)
calc = total - sym
smtp = Mid$(txtSMTP.Text, sym + 1, calc)
wskEmail.Close 'just in case it was left open for some reason, reset it before connect
wskEmail.Connect txtSMTP.Text, 25
Do While wskEmail.State <> sckConnected 'wait until we
DoEvents 'are connected to
Loop 'send the email
'gotta use vbcr, not vbcrlf....or it won't work...
wskEmail.SendData "HELO " & smtp & vbCr
wskEmail.SendData "Mail from: " & txtFrom.Text & vbCr
wskEmail.SendData "Rcpt to: " & txtTo.Text & vbCr
wskEmail.SendData "data" & vbCr
wskEmail.SendData "Subject: " & txtSubj.Text & vbCr
wskEmail.SendData txtMsg.Text & vbCr
wskEmail.SendData "." & vbCr
wskEmail.SendData "quit" & vbCr
wskEmail.Close
MsgBox "Done"
End Sub
|
|