Solved

E-mail using winsock

Posted on 1998-12-28
2
339 Views
Last Modified: 2013-12-25
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
Comment
Question by:huangxb
2 Comments
 

Accepted Solution

by:
jmnolan earned 50 total points
ID: 1498578
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
 

Author Comment

by:huangxb
ID: 1498579
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now