vlakshmi
Jul 19th, 1999, 12:10 PM
Hi,
I tried sending mails using winsock, but it would not work Is it because my port number is wrong.
help...
thanks
laks
Sub SendEmail()
Dim datenow As String, first As String, second As String, third As String, fourth As String, fifth As String, sixth As String, seventh As String, ninth As String, eighth As String
Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail per program start
If Winsock1.State = sckClosed Then ' Check to see if socet is closed
datenow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
first = "mail from:" + Chr(32) + "vlakshmi@mdr.com.sg" + vbCrLf ' Get who's sending E-Mail address
second = "rcpt to:" + Chr(32) + "vlakshmi@mdr.com.sg" + vbCrLf ' Get who mail is going to
third = "Date:" + Chr(32) + datenow + vbCrLf ' Date when being sent
fourth = "From:" + Chr(32) + "v.Lakshmi" + vbCrLf ' Who's Sending
fifth = "To:" + Chr(32) + "vl" + vbCrLf ' Who it going to
sixth = "Subject:" + Chr(32) + "test" + vbCrLf ' Subject of E-Mail
seventh = "testing" + vbCrLf ' E-mail message body
ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf ' What program sent the e-mail, customize this
eighth = fourth + third + ninth + fifth + sixth ' Combine For proper SMTP sending
Winsock1.Protocol = sckTCPProtocol ' Set protocol For sending
Winsock1.RemoteHost = "203.120.90.45" ' Set the server address
Winsock1.RemotePort = 80 ' Set the SMTP Port
Winsock1.Connect ' Start connection
WaitFor ("220")
status.Caption = "Connecting...."
status.Refresh
Winsock1.SendData ("HELLO yourdomain.com" + vbCrLf)
WaitFor ("250")
status.Caption = "Connected"
status.Refresh
Winsock1.SendData (first)
status.Caption = "Sending Message"
status.Refresh
WaitFor ("250")
Winsock1.SendData (second)
WaitFor ("250")
Winsock1.SendData ("data" + vbCrLf)
WaitFor ("354")
Winsock1.SendData (eighth + vbCrLf)
Winsock1.SendData (seventh + vbCrLf)
Winsock1.SendData ("." + vbCrLf)
WaitFor ("250")
Winsock1.SendData ("quit" + vbCrLf)
status.Caption = "Disconnecting"
status.Refresh
WaitFor ("221")
Winsock1.Close
Else
MsgBox (Str(Winsock1.State))
End If
End Sub
Sub WaitFor(ResponseCode As String)
Dim start, response, tmr, msgtitle
start = Timer ' Time Event so won't Get stuck in Loop
While Len(response) = 0
tmr = start - Timer
DoEvents ' Let System keep checking For incoming response **IMPORTANT**
If tmr > 50 Then ' Time in seconds to wait
MsgBox "SMTP service error, timed out While waiting For response", 64, msgtitle
Exit Sub
End If
Wend
While Left(response, 3) <> ResponseCode
DoEvents
If tmr > 50 Then
MsgBox "SMTP service error, improper response code. Code should have been: " + ResponseCode + " Code recieved: " + response, 64, msgtitle
Exit Sub
End If
Wend
response = "" ' Sent response code to blank **IMPORTANT**
End Sub
Private Sub Command1_Click()
status.Caption = "Please wait... contacting smtp.pacific.net.sg"
SendEmail 'txtemailserver.Text, txtfromName.Text, txtfromemailaddress.Text, txttoemailaddress.Text, txttoemailaddress.Text, txtemailsubject.Text, txtemailbodyofmessage.Text
'MsgBox ("Mail Sent")
status.Caption = "Mail Sent"
status.Refresh
Beep
Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim response
Winsock1.GetData response ' Check For incoming response *IMPORTANT*
End Sub
I tried sending mails using winsock, but it would not work Is it because my port number is wrong.
help...
thanks
laks
Sub SendEmail()
Dim datenow As String, first As String, second As String, third As String, fourth As String, fifth As String, sixth As String, seventh As String, ninth As String, eighth As String
Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail per program start
If Winsock1.State = sckClosed Then ' Check to see if socet is closed
datenow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
first = "mail from:" + Chr(32) + "vlakshmi@mdr.com.sg" + vbCrLf ' Get who's sending E-Mail address
second = "rcpt to:" + Chr(32) + "vlakshmi@mdr.com.sg" + vbCrLf ' Get who mail is going to
third = "Date:" + Chr(32) + datenow + vbCrLf ' Date when being sent
fourth = "From:" + Chr(32) + "v.Lakshmi" + vbCrLf ' Who's Sending
fifth = "To:" + Chr(32) + "vl" + vbCrLf ' Who it going to
sixth = "Subject:" + Chr(32) + "test" + vbCrLf ' Subject of E-Mail
seventh = "testing" + vbCrLf ' E-mail message body
ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf ' What program sent the e-mail, customize this
eighth = fourth + third + ninth + fifth + sixth ' Combine For proper SMTP sending
Winsock1.Protocol = sckTCPProtocol ' Set protocol For sending
Winsock1.RemoteHost = "203.120.90.45" ' Set the server address
Winsock1.RemotePort = 80 ' Set the SMTP Port
Winsock1.Connect ' Start connection
WaitFor ("220")
status.Caption = "Connecting...."
status.Refresh
Winsock1.SendData ("HELLO yourdomain.com" + vbCrLf)
WaitFor ("250")
status.Caption = "Connected"
status.Refresh
Winsock1.SendData (first)
status.Caption = "Sending Message"
status.Refresh
WaitFor ("250")
Winsock1.SendData (second)
WaitFor ("250")
Winsock1.SendData ("data" + vbCrLf)
WaitFor ("354")
Winsock1.SendData (eighth + vbCrLf)
Winsock1.SendData (seventh + vbCrLf)
Winsock1.SendData ("." + vbCrLf)
WaitFor ("250")
Winsock1.SendData ("quit" + vbCrLf)
status.Caption = "Disconnecting"
status.Refresh
WaitFor ("221")
Winsock1.Close
Else
MsgBox (Str(Winsock1.State))
End If
End Sub
Sub WaitFor(ResponseCode As String)
Dim start, response, tmr, msgtitle
start = Timer ' Time Event so won't Get stuck in Loop
While Len(response) = 0
tmr = start - Timer
DoEvents ' Let System keep checking For incoming response **IMPORTANT**
If tmr > 50 Then ' Time in seconds to wait
MsgBox "SMTP service error, timed out While waiting For response", 64, msgtitle
Exit Sub
End If
Wend
While Left(response, 3) <> ResponseCode
DoEvents
If tmr > 50 Then
MsgBox "SMTP service error, improper response code. Code should have been: " + ResponseCode + " Code recieved: " + response, 64, msgtitle
Exit Sub
End If
Wend
response = "" ' Sent response code to blank **IMPORTANT**
End Sub
Private Sub Command1_Click()
status.Caption = "Please wait... contacting smtp.pacific.net.sg"
SendEmail 'txtemailserver.Text, txtfromName.Text, txtfromemailaddress.Text, txttoemailaddress.Text, txttoemailaddress.Text, txtemailsubject.Text, txtemailbodyofmessage.Text
'MsgBox ("Mail Sent")
status.Caption = "Mail Sent"
status.Refresh
Beep
Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim response
Winsock1.GetData response ' Check For incoming response *IMPORTANT*
End Sub