• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

E-mail using winsock

I want to send e-mail using VB 5.0
The expert, mysqlG has said:

Using VB and assuming the computer you run it from
   has internet access.  Its a very simple thing using
   the SMTP and winsck.ocx.
   From memory its as easy as.
   add a winsock control to the form
   set it up using your mail server and set it to       tcpprotocol (0)
   and port 25..
   then connect
   and:

   Winsock1.SendData "HELO your.mail.server" & vbCrLf
   Winsock1.SendData "mail from: youremail" & vbCrLf
   Winsock1.SendData "RCPT To:" & whoeverinvar & vbCrLf
   Winsock1.SendData "data" & vbCrLf
   Winsock1.SendData "the text you wanna send" & vbCrLf
   Winsock1.SendData vbCrLf & "." & vbCrLf
   its that simple..

------------------------------------------
I try this , but I can't do it.
I will appreciate if the expert can send me the source sample Or give me the more suggestion.
Please E-mail to huangxb@usa.net
0
huangxb
Asked:
huangxb
1 Solution
 
jmnolanCommented:
well..  I see a small problem with that code. First of all is the problem with conecting to port 25 or does it connect and just not work? That code is correct except that this line:

Winsock1.SendData "RCPT To:" & whoeverinvar & vbCrLf

should read:

Winsock1.SendData "RCPT To:<" & whoeverinvar & ">" & vbCrLf
(add angle-brackets around the address)

you should also send this when you are done:

Winsock1.SendData "quit" & vbCrLf

0
 
huangxbAuthor Commented:
I have not successed following the suggestion of the expert, jmnolan
Please give me more suggestion or send me a sample
Thanks.

-----------------------------------------

Situation:
      Mail host:    mail.csair.com   Microsoft Exchange server 5.5
      User E-mail address:   huangxb@csair.com
      PC:   win95
The following is my VB5.0 program, It can connect to the port 25 of
the remote mail host( mail.csair.com) and send all the data


Dim blnCompleted As Boolean

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdSend_Click()
Dim i As Long
Dim e
Dim whoeverinvar As String
blnCompleted = False
If cmdSend.Caption = "Send" Then
  cmdSend.Caption = "Stop"
  cmdExit.Enabled = False
Else
  blnStop = True
  Exit Sub
End If
blnStop = False

If Winsock1.State <> sckClosed Then
  Winsock1.Close
End If
If Winsock1.State = 0 Then
   Winsock1.Connect
End If

Text1.Text = "Connecting remote host"
Do While Winsock1.State <> sckConnected
  e = DoEvents
  If blnStop = True Then
     If Winsock1.State <> sckClosed Then
        Winsock1.Close
     End If
     Text1 = "Connection has been stoped"
     cmdSend.Caption = "OK"
     cmdExit.Enabled = True
     Exit Sub
  End If
Loop
Text1 = "Remote host connected"

   whoeverinvar = "huangxb@csair.com"
   Winsock1.SendData "HELO mail.csair.com" & vbCrLf
   Winsock1.SendData "mail from:huangxb@csair.com" & vbCrLf
   'Winsock1.SendData "RCPT To:huangxb@csair.com" & whoeverinvar & vbCrLf
   Winsock1.SendData "RCPT To:<" & whoeverinvar & ">" & vbCrLf
   'Winsock1.SendData "RCPT To:<huangxb@csair.com>" & vbCrLf
   Winsock1.SendData "data" & vbCrLf
   Winsock1.SendData "the text you wanna send " & vbCrLf
   Winsock1.SendData vbCrLf & "." & vbCrLf
   Winsock1.SendData "quit" & vbCrLf
Do While blnCompleted = False
  e = DoEvents
  If blnStop = True Then
     Text1 = "Stoped"
     Winsock1.Close
    cmdOK.Caption = "Send"
    cmdExit.Enabled = True
    Exit Sub
  End If
Loop
Winsock1.Close
Text1 = "Closed"
cmdSend.Caption = "Send"
cmdExit.Enabled = True
MsgBox "OK"
End Sub

Private Sub Winsock1_SendComplete()
blnCompleted = True
End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now