hello,
i got one code for sending mails through vb. th code is as follows
Option Explicit
Private nConnected As Boolean
'Private WithEvents Winsock1 As Winsock
Private ptRetCode As Boolean
Public Event Status(txtStatus As String)
Sub SendBrainDead(txtServer As String, szEmailFrom As String, szNameFrom As String, szEmailTo As String, szNameTo As String, szSubject As String, szMsg As String)
'txtServer smtp.mailserver.com
'szEmailFromyourname@bus.com the persons email address thats send
' ing the email
'szNameFromJohn Doe Your real name or even your alias
'szEmailTo recieving~party@their~pop.net Person your sending an e
' -mail to
'szNameTo Annie Doe reciever's name.
'szSubject This will show as the subject in the message.
'szMsg This is ofcourse the place you put you message.
'NOTE: I do not do any MIME or BASE64 in this code if someone cre
' ates an OCX for this
'i'd love a copy.
'-- This routine sends an email message via an SMTP gateway.
If Not nConnected Then 'Check to see if its a used control
InitIt txtServer
End If
Dim szCRLF As String
Dim szCompleteMsg As String
'-- All lines end with a CR/LF Pair
szCRLF = Chr$(13) & Chr$(10)
'-- Construct the data as a 4-line header (Date, From,
'To, and Subject) followed by the message text
szCompleteMsg = "DATE: " & Format$(Now, "dd mmm yy ttttt") & szCRLF
szCompleteMsg = szCompleteMsg & "FROM: " & szNameFrom & szCRLF
szCompleteMsg = szCompleteMsg & "TO: " & szNameTo & szCRLF
szCompleteMsg = szCompleteMsg & "SUBJECT: " & szSubject & szCRLF & szCRLF
szCompleteMsg = szCompleteMsg & szMsg & szCRLF
'-- Wait for a response,don't just send blindly
Winsock1.SendData "HELO " & Winsock1.LocalHostName & szCRLF
WaitLoop
Winsock1.SendData "MAIL FROM: <" & szEmailFrom & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "RCPT TO: <" & szEmailTo & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "DATA" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData szCompleteMsg & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "." & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
'Clean up the control
Winsock1.SendData "QUIT" & szCRLF
Winsock1.Close
Winsock1.RemotePort = 0
Winsock1.LocalPort = 0
'Set Winsock1 = Nothing
nConnected = False
End Sub
Private Sub Form_Load()
'SendBrainDead(txtServer As String, szEmailFrom As String, szNameFrom As String, szEmailTo As String, szNameTo As String, szSubject As String, szMsg As String)
Call InitIt("server ip address")
Call SendBrainDead("server ip address", "abc@xyz.com", "Ganu", "xyz@abc.com", "ajay", "hi test", "test msg with ")
End Sub
Private Sub Winsock1_Connect()
nConnected = True
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strRet As String
Winsock1.GetData strRet, vbString, bytesTotal
RaiseEvent Status(strRet)
ptRetCode = True
End Sub
Private Sub InitIt(txtServer As String)
'-- Temporarily disable the button
'Set Winsock1 = Winsock1
Screen.MousePointer = vbHourglass
'btnSend.Enabled = False
'-- SMTP uses port 25
Winsock1.RemotePort = 25
Winsock1.RemoteHost = txtServer
'-- Try to connect
nConnected = False
'On Error Resume Next
Winsock1.Connect
Do
DoEvents
Loop Until nConnected
Screen.MousePointer = vbNormal
End Sub
Private Sub WaitLoop()
'Wait for a return
'I DONT check return values
'You should do some error protection.
Do Until ptRetCode = True
DoEvents
Loop
ptRetCode = False
End Sub
this code runs without any error but i am not receiving any mails.
please tell me what is error.
Ajay
i got one code for sending mails through vb. th code is as follows
Option Explicit
Private nConnected As Boolean
'Private WithEvents Winsock1 As Winsock
Private ptRetCode As Boolean
Public Event Status(txtStatus As String)
Sub SendBrainDead(txtServer As String, szEmailFrom As String, szNameFrom As String, szEmailTo As String, szNameTo As String, szSubject As String, szMsg As String)
'txtServer smtp.mailserver.com
'szEmailFromyourname@bus.com the persons email address thats send
' ing the email
'szNameFromJohn Doe Your real name or even your alias
'szEmailTo recieving~party@their~pop.net Person your sending an e
' -mail to
'szNameTo Annie Doe reciever's name.
'szSubject This will show as the subject in the message.
'szMsg This is ofcourse the place you put you message.
'NOTE: I do not do any MIME or BASE64 in this code if someone cre
' ates an OCX for this
'i'd love a copy.
'-- This routine sends an email message via an SMTP gateway.
If Not nConnected Then 'Check to see if its a used control
InitIt txtServer
End If
Dim szCRLF As String
Dim szCompleteMsg As String
'-- All lines end with a CR/LF Pair
szCRLF = Chr$(13) & Chr$(10)
'-- Construct the data as a 4-line header (Date, From,
'To, and Subject) followed by the message text
szCompleteMsg = "DATE: " & Format$(Now, "dd mmm yy ttttt") & szCRLF
szCompleteMsg = szCompleteMsg & "FROM: " & szNameFrom & szCRLF
szCompleteMsg = szCompleteMsg & "TO: " & szNameTo & szCRLF
szCompleteMsg = szCompleteMsg & "SUBJECT: " & szSubject & szCRLF & szCRLF
szCompleteMsg = szCompleteMsg & szMsg & szCRLF
'-- Wait for a response,don't just send blindly
Winsock1.SendData "HELO " & Winsock1.LocalHostName & szCRLF
WaitLoop
Winsock1.SendData "MAIL FROM: <" & szEmailFrom & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "RCPT TO: <" & szEmailTo & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "DATA" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData szCompleteMsg & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "." & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
'Clean up the control
Winsock1.SendData "QUIT" & szCRLF
Winsock1.Close
Winsock1.RemotePort = 0
Winsock1.LocalPort = 0
'Set Winsock1 = Nothing
nConnected = False
End Sub
Private Sub Form_Load()
'SendBrainDead(txtServer As String, szEmailFrom As String, szNameFrom As String, szEmailTo As String, szNameTo As String, szSubject As String, szMsg As String)
Call InitIt("server ip address")
Call SendBrainDead("server ip address", "abc@xyz.com", "Ganu", "xyz@abc.com", "ajay", "hi test", "test msg with ")
End Sub
Private Sub Winsock1_Connect()
nConnected = True
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strRet As String
Winsock1.GetData strRet, vbString, bytesTotal
RaiseEvent Status(strRet)
ptRetCode = True
End Sub
Private Sub InitIt(txtServer As String)
'-- Temporarily disable the button
'Set Winsock1 = Winsock1
Screen.MousePointer = vbHourglass
'btnSend.Enabled = False
'-- SMTP uses port 25
Winsock1.RemotePort = 25
Winsock1.RemoteHost = txtServer
'-- Try to connect
nConnected = False
'On Error Resume Next
Winsock1.Connect
Do
DoEvents
Loop Until nConnected
Screen.MousePointer = vbNormal
End Sub
Private Sub WaitLoop()
'Wait for a return
'I DONT check return values
'You should do some error protection.
Do Until ptRetCode = True
DoEvents
Loop
ptRetCode = False
End Sub
this code runs without any error but i am not receiving any mails.
please tell me what is error.
Ajay