Posted on 1999-01-09
Last Modified: 2010-05-03
Could any one please help me by giving me the full source code to send E-Mail in VB3.  It must be in VB3.  Any thing that works is great. Just need to send an email through VB3.
Question by:marka64

Expert Comment

ID: 1455071
have a look at

I'll Post the zip file their.

Accepted Solution

Vingamel earned 200 total points
ID: 1455072
Try this and see if works for you.  I am not certain if this will work in VB3 since I don't have VB3 to test it, but holler if you need more info.  I'll try to help if I can.  --Vingamel

Dim Response As String, Reply As Integer, DateNow As String
Dim first As String, Second As String, Third As String
Dim Fourth As String, Fifth As String, Sixth As String
Dim Seventh As String, Eighth As String
Dim Start As Single, Tmr As Single

Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage 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) + FromEmailAddress + vbCrLf ' Get who's sending E-Mail address
        Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf ' Get who mail is going to
        Third = "Date:" + Chr(32) + DateNow + vbCrLf ' Date when being sent
        Fourth = "From:" + Chr(32) + FromName + vbCrLf ' Who's Sending
        Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf ' Who it going to
        Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf ' Subject of E-Mail
        Seventh = EmailBodyOfMessage + 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 = MailServerName ' Set the server address
        Winsock1.RemotePort = 25 ' Set the SMTP Port
        Winsock1.Connect ' Start connection
        WaitFor ("220")
        StatusTxt.Caption = "Connecting...."
        Winsock1.SendData ("HELO" + vbCrLf)
        WaitFor ("250")
        StatusTxt.Caption = "Connected"
        Winsock1.SendData (first)
        StatusTxt.Caption = "Sending Message"
        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)
        StatusTxt.Caption = "Disconnecting"
        WaitFor ("221")
        MsgBox (Str(Winsock1.State))
    End If

End Sub

Sub WaitFor(ResponseCode As String)

    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


        While Left(Response, 3) <> ResponseCode


                If Tmr > 50 Then
                    MsgBox "SMTP service error, impromper response code. Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
                    Exit Sub
                End If


            Response = "" ' Sent response code to blank **IMPORTANT**
        End Sub

Private Sub Command1_Click()

    SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
    'MsgBox ("Mail Sent")
    StatusTxt.Caption = "Mail Sent"
End Sub

Private Sub Command2_Click()

End Sub

Private Sub Form_Load()

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Winsock1.GetData Response ' Check for incoming response *IMPORTANT*
End Sub


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

808 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