Stand alone email client for pop3 email


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Stand alone email client for pop3 email

  1. #1
    Join Date
    Mar 2006
    Posts
    2

    Question Stand alone email client for pop3 email

    Hi folks. I have been searching for a starting point on trying to figure out how to write my own simple email client for both sending and receiving email through internet pop3 email accounts.

    From what I can see so far, MAPI is not going to help me as it requires Echange and or Outlook or something like that. I am not looking to depend on or interact with any other email program. I am basically trying to write my own.

    I have been using VB and QB and GWB for years, but I have never wrote anything that involved the internet. They have all be pretty simple programs. I have also been webmastering for a few years now, but once again it has been pretty simple stuff. Mostly just HTML, some CSS, JavaScript, PHP. But, nothing very complicated or hard.

    I am hoping that someone can help me figure out how to write VB6 code to both send and receive email through a email (pop3) account. I am not going to guarantee that I am using the correct terminology when I say POP3, so here it is in a nutshell. Assuming that I already have an internet connection, I want to be able to login to an email account that I create with my hosting service using my username and password. Of course, I would also know the incoming mail server address (typically mail.mydomain.com) and my outgoing mail server address (typically smtp.myisp.com).

    If you can tell me how to do this, it would be great. If not, if you know where I could find this information, that would be great too.

    Thanks,
    Luke

  2. #2
    Join Date
    Feb 2006
    Posts
    19
    Here is a class you can use to send email from VB. I wrote it years ago, but have seen a few requests for info on emailing.
    Here is an example of how to use the class

    Edit: Before using the class you'll have to add a refernce to MSWINSCK.OCX
    Goto Project\References Browse to system32\MSWINSOCK.OCX

    visual basic code:Option Explicit

    Private WithEvents SMTP As clsSMTP

    Private Sub Command1_Click()

    With SMTP
    'who is the email from?
    .Sender = "YoMama"
    'who is it going to?
    .Recipient = "whomever@whereever.net"
    'your SMTP server
    .SMTPhost = "smtp.myserver.com"
    'optional subject line
    .Subject = "SMTP test"
    'make connection to the server
    .OpenMail
    'did connection succeed?
    If Not .Connected Then Exit Sub
    'you can send as many lines as you want here
    .Send "Bill,"
    .Send "This is a test of your wonderful SMTP client!"
    'make sure you close or nothing will get sent
    .CloseMail
    End With

    End Sub

    Private Sub Form_Load()
    Set SMTP = New clsSMTP
    End Sub


    Private Sub SMTP_Error(Code As Integer, Message As String)
    Debug.Print "SMTP Error "; Code, Message
    End Sub

    Private Sub SMTP_ServerResponse(Reply As Integer, Message As String)
    Debug.Print Reply, Message
    End Sub


    Pretty simple, Now here is the class

    visual basic code:Option Explicit

    Private mvarConnected As Boolean
    Private mvarRecipient As String
    Private mvarSender As String
    Private mvarSMTPhost As String
    Private mvarSubject As String

    Private WithEvents Winsock As MSWinsockLib.Winsock

    Const OK = 250
    Const Connection = 220
    Const ReadyforData = 354
    Const UserUnknown = 550

    Dim Reply As Integer
    Dim Message As String
    Dim MyName As String
    Dim ErrMSg As String

    Event Error(Code As Integer, Message As String)
    Event ServerResponse(Reply As Integer, Message As String)

    Private Function WaitFor(R As Integer) As Boolean
    Dim A
    A = Timer + 3
    While Not Reply = R And A > Timer
    DoEvents
    Wend
    If A < Timer Then
    WaitFor = True
    Else
    WaitFor = False
    End If
    Reply = 0
    End Function

    Public Property Let Subject(ByVal vData As String)
    mvarSubject = vData
    End Property

    Public Property Get Subject() As String
    Subject = mvarSubject
    End Property

    Public Property Let SMTPhost(ByVal vData As String)
    mvarSMTPhost = vData
    End Property

    Public Property Get SMTPhost() As String
    SMTPhost = mvarSMTPhost
    End Property

    Public Sub Send(Message As String)
    Winsock.SendData Message & vbCrLf
    End Sub

    Public Property Let Sender(ByVal vData As String)
    mvarSender = vData
    End Property

    Public Property Get Sender() As String
    Sender = mvarSender
    End Property

    Public Property Let Recipient(ByVal vData As String)
    mvarRecipient = vData
    End Property

    Public Property Get Recipient() As String
    Recipient = mvarRecipient
    End Property

    Public Property Get Connected() As Boolean
    Connected = mvarConnected
    End Property

    Public Sub OpenMail()
    Reply = 0
    'connect to SMTP server
    Winsock.Connect mvarSMTPhost, 25
    If WaitFor(Connection) Then
    GiveError
    Exit Sub
    End If
    'send hello and wait for OK
    Winsock.SendData "helo " & mvarSMTPhost & vbCrLf
    If WaitFor(OK) Then
    GiveError
    Winsock.Close
    Exit Sub
    End If
    'send sender's name
    MyName = WhoAmI
    If InStr(mvarSender, "@") = 0 Then
    Winsock.SendData "Mail From:<" & mvarSender & "@" & MyName & ">" & vbCrLf
    Else
    Winsock.SendData "Mail From:<" & mvarSender & ">" & vbCrLf
    End If
    If WaitFor(OK) Then
    GiveError
    Winsock.Close
    Exit Sub
    End If
    'send recipient
    Winsock.SendData "RCPT TO:<" & mvarRecipient & ">" & vbCrLf
    If WaitFor(OK) Then
    GiveError
    Winsock.Close
    Exit Sub
    End If
    'make ready for data
    Winsock.SendData "Data" & vbCrLf
    If WaitFor(ReadyforData) Then
    GiveError
    Winsock.Close
    Exit Sub
    End If
    'Send Date:
    Winsock.SendData "Date: " & Format(Date, " dd mmm yy ") & Time & vbCrLf
    'To:
    Winsock.SendData "TO:<" & mvarRecipient & ">" & vbCrLf
    'From:
    Winsock.SendData "From: <" & mvarSender & "@" & MyName & ">" & vbCrLf
    'Subject:
    If Not mvarSubject = "" Then Winsock.SendData "Subject:" & mvarSubject & vbCrLf
    mvarConnected = True
    End Sub

    Private Function WhoAmI() As String
    Dim X As Integer, Y As Integer
    X = InStr(Message, "Hello")
    Y = InStr(Message, "[")
    If X = 0 Or Y = 0 Then
    WhoAmI = Winsock.LocalIP
    Else
    X = X + 6
    Y = Y - 1 - X
    WhoAmI = Mid$(Message, X, Y)
    End If
    End Function

    Public Sub CloseMail()
    Winsock.SendData "." & vbCrLf
    If WaitFor(OK) Then
    GiveError
    Exit Sub
    End If
    Winsock.SendData "QUIT"
    Winsock.Close
    End Sub

    Private Sub GiveError()
    Dim Message As String
    Select Case Reply
    Case Is = 10061
    Message = "Can't Connect to " & mvarSMTPhost
    Case Is = 11001
    Message = mvarSMTPhost & " is not a valid name or address."
    Case Is = 550
    Message = "User " & mvarRecipient & " not known to server."
    Case Is = 0
    Message = "Timeout waiting for server response"
    Case Is = 500
    Message = "Server does not recognize a command sent."
    Case Is = 553
    Message = "Invalid recipient name"
    Case Is = 1
    Message = "You must set Host, Recipient and Sender before connecting"
    Case Else
    Message = "Mail tool error."
    End Select

    RaiseEvent Error(Reply, Message)
    End Sub

    Private Sub Class_Initialize()
    Set Winsock = New MSWinsockLib.Winsock
    End Sub

    Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    Dim X As String
    Winsock.GetData X
    Reply = Val(X)
    X = Trim$(Mid(X, 4))
    RaiseEvent ServerResponse(Reply, X)
    Message = X
    End Sub

    Private Sub Winsock_Error(ByVal Number As Integer, Description As String, _
    ByVal Scode As Long, ByVal Source As String, _
    ByVal HelpFile As String, ByVal HelpContext As Long, _
    CancelDisplay As Boolean)
    Reply = Number
    End Sub

    PS iam not this clever...
    goto http://www.vbforums.com/showthread.p...t=email+client

    and search for email clients

Similar Threads

  1. Web-Based Email Client
    By Chief Wun in forum Architecture and Design
    Replies: 0
    Last Post: 07-03-2001, 09:48 PM
  2. Replies: 0
    Last Post: 01-09-2001, 01:26 PM
  3. opening default Email client
    By Josh in forum VB Classic
    Replies: 4
    Last Post: 11-21-2000, 11:58 AM
  4. opening default Email client
    By Josh in forum VB Classic
    Replies: 0
    Last Post: 11-20-2000, 05:01 PM
  5. Problems for install proxy client ....
    By Armando Cardenas in forum VB Classic
    Replies: 0
    Last Post: 07-19-2000, 10:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center