POP3 mail getting, Smtp Sending

Posted on 1998-06-11
Last Modified: 2013-11-13
How can I get Mails from a POP3 Server ad send mails trough a SMTP Server with VB 5.0?
Question by:mas11
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

ID: 1463164
Edited text of question

Accepted Solution

seahpc earned 100 total points
ID: 1463165
For Receving mails, I will reference you to a site later.
For Sending mails, I will atttach the codes below .
Hope it helps .
You will need some textboxes, label, winsock control and a command button

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

        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
       StatusTxt.Caption = "Mail Sent"
End Sub

Private Sub Command2_Click()
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
       Winsock1.GetData Response ' Check for incoming response *IMPORTANT*
End Sub


Author Comment

ID: 1463166
Which site did you, seahpc, want to refrence to me?

Thanx for your answer!! Really helped!

Expert Comment

ID: 1463167
Hi, mas11

The site that I recommend is
Heard of this site ?
It has hundreds of codes for VB and JavaScript .
One of the topic is receiving and sending of mail .
I try to search for it but my company network is down but I am sure it is there .
Try going into this site and browse through all topics .
Today wil ltry to search the exact location for you .


Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

726 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