Solved

E-mail using winsock

Posted on 1998-12-28
2
337 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

22 Experts available now in Live!

Get 1:1 Help Now