1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

email from vb6

Discussion in 'Software Development' started by wes peters, Jan 16, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. wes peters

    wes peters Thread Starter

    Joined:
    Nov 5, 2002
    Messages:
    29
    I don't know if my other post went through, I can't find it, so I'll try again. Sorry If it did go through I don't mean to double post.

    I'm having trouble emailing directly from vb6. In my App. I open two different files, get there info, do some calculations and email the results to my client. My problem is that my email code only sends the info to my Microsoft Outlook. I then have to open Outlook and hit the send button and away it goes.

    Here is my code:

    Dim olapp As Object, oitem As Object
    Dim confirm As Integer
    On Error GoTo ErrHandler
    Set olapp = CreateObject("Outlook.Application")
    Set oitem = olapp.CreateItem(0)
    If olapp Is Nothing Then ''' True if not running
    Set olapp = CreateObject("Outlook.Application")
    End If
    confirm = MsgBox("Email this to customer?", vbOKCancel, "Confirmation")
    If confirm = 1 Then
    emadd = InputBox("Enter E-mail Address", "E-mail Address", Email)
    With oitem
    .Subject = "Window Quote"
    .To = emadd
    .Body = frmCustDat.Text1.Text
    .Send
    End With

    ''' Close the email document
    Set olapp = Nothing
    ''' Quite the email application
    Set oitem = Nothing
    Else
    MsgBox "Email not sent", vbOKCancel, "Cancel"
    End If
    ErrHandler:
    Unload Me
    End Sub

    I have also tried MAPI code and it does the same thing.
    Most of the email code isn't mine, but it seems to work to some extent.

    Thanks, again for any and all help.
     
  2. AbvAvgUser

    AbvAvgUser

    Joined:
    Oct 3, 2002
    Messages:
    2,281
    So far all the e-mail links that I have had from VB Applications have been doing what you say. It places a message in the Outbox of the Default Mail Client.

    However, if you wish to send a mail directly from your Applications, your application will have to connect directly to the SMTP servers of your ISP. That will be like writing something similar to a mail client. Do you really want to do that? Is it worth the effort? Thats for you to decide.

    However, I have an article downloaded from some site which shows how to write a POP3 mail client in VB. It is a set of 5 pages in HTML format. I don't think it is complete, but you can get some hint from it. FYI, it uses WinSock controls.

    If you want that articles, send me a private message and give me your mail address, I will zip and e-mail it to you.
     
  3. wes peters

    wes peters Thread Starter

    Joined:
    Nov 5, 2002
    Messages:
    29
    Thanks for all your help.

    I got it all worked out and can email directly from vb6.

    Here is my code if anybody is interested:

    Dim ol As Object
    Dim olns As Object
    Dim objFolder As Object
    Dim objAllContacts As Object
    Dim Contact As Object
    ' Set the application object
    Set ol = New Outlook.Application
    ' Set the namespace object
    Set olns = ol.GetNamespace("MAPI")
    ' Set the default Contacts folder
    Set objFolder = olns.GetDefaultFolder(olFolderContacts)
    ' Set objAllContacts = the collection of all contacts
    Set objAllContacts = objFolder.Items
    ' Loop through each contact
    For Each Contact In objAllContacts
    ' Display the Fullname field for the contact
    'MsgBox Contact.FullName
    Next
    Dim olApp As Outlook.Application
    Dim olItem As Outlook.MailItem
    Dim confirm As Integer
    Dim emadd As String

    On Error GoTo ErrHandler
    confirm = MsgBox("Email this to customer?", vbOKCancel, "Confirmation")
    If confirm = 1 Then
    emadd = InputBox("Enter E-mail Address", "E-mail Address", Email)
    Set olApp = CreateObject("Outlook.Application")
    Set olItem = olApp.CreateItem(olMailItem)
    With olItem
    .Subject = "Window Quote"
    .To = emadd
    .body = frmCustDat.Text1.Text
    .Send
    End With
    ''' Close the email document
    Set olItem = Nothing
    ''' Quite the email application
    olApp.Quit
    Set olApp = Nothing
    Else
    MsgBox "Email not sent", vbOKCancel, "Cancel"
    End If
    ErrHandler:
    Unload Me
     
  4. AbvAvgUser

    AbvAvgUser

    Joined:
    Oct 3, 2002
    Messages:
    2,281
    That's cool!! :p

    Can you please mail me your form that contains the code? If yes, I will send you my e-mail address in a private message. Or do you have it with you? I am the one who sent you the articles on writing a POP3 client in VB. Was that of any use?
     
  5. wes peters

    wes peters Thread Starter

    Joined:
    Nov 5, 2002
    Messages:
    29
    Well I almost have this email thing working perfectly.
    first I deleted the first 18 lines of the code in my post since it isn't needed because you only need a reference to the Outlook Library, so all is well there but I have two
    "little irritations" with my email code.

    1. The first time I use my App. and email from vb I have to go into Outlook and hit the "send" to send my email. After that I can send emails directly from vb with no problems.

    2. After a few uses I find that my Outlook hangs up.
    Could this be because it's not closeing properly?

    Like I said these are only minor irritations that I can live with if I have to, but being a perfectionist I know it should work better. Does any one have any ideas for me to try.

    Thanks again for all your help, we're almost there.

    wes
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/113660

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice