Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2003, 02:05 PM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Troubles using MAPI email in VB6

I need to start a MAPI session to send email from a VB6 app, and to do that, I need to find the name of the installed default email client (Outlook, Outlook Express, etc). Does anyone know where to look in the registry to find the name of the local email client? I don't want the user to have to select the default email client each time they want to send an email.

Here is the pseudo-code for what I am doing:

Code:
'Create an object of the Session
Set m_objSession = CreateObject(MAPI_SESSION)
'try to logon to an existing open email system - if one is not running
'then we will try some other options in the errorhandler
m_objSession.Logon ShowDialog:=False, Newsession:=False
'if that fails, then in the error handler, find the default
'profile in the registry and then try
m_objSession.Logon ProfileName:=DefaultMapiProfile, ShowDialog:=False, Newsession:=True
I found a post on this a year ago, but since the wrox site has changed I cannot search/find that post again. The code from that post was correct in finding the default email profile for Win2K and NT in the registry at HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Windows Messaging Subsystem\Profiles. However, I either mistyped the location for Win9x systems or the info was wrong and not fully tested because I now get errors.

Thanks!

Mark Phillips
 
Old August 12th, 2003, 01:29 AM
Authorized User
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, I found the code in the Microsoft Knowledge Base - article 171422 (http://support.microsoft.com/default...b;en-us;171422).

This is the code snippet that is giving me a headache:
Code:
      Sub StartMessagingAndLogon()
         Dim sKeyName As String
         Dim sValueName As String
         Dim sDefaultUserProfile As String
         Dim osinfo As OSVERSIONINFO
         Dim retvalue As Integer

         On Error GoTo ErrorHandler
         Set objSession = CreateObject("MAPI.Session")

         'Try to logon.  If it fails, the most likely reason is that you do
         'not have an open session.  Error -2147221231  MAPI_E_LOGON_FAILED 
         'will return.  Trap the error in the ErrorHandler 
         objSession.Logon ShowDialog:=False, NewSession:=False
         Exit Sub
      ErrorHandler:
         Select Case Err.Number
            Case -2147221231  'MAPI_E_LOGON_FAILED
               'Need to find out what OS is in use, the keys are different
               'for WinNT and Win95.
               osinfo.dwOSVersionInfoSize = 148
               osinfo.szCSDVersion = Space$(128)
               retvalue = GetVersionEx(osinfo)
               Select Case osinfo.dwPlatformId
                  Case 0   'Unidentified
                     MsgBox "Unidentified Operating System.  " & _
                        "Can't log onto messaging."
                     Exit Sub
                  Case 1   'Win95 (this key does not exist!!)
                     sKeyName = "Software\Microsoft\" & _
                                "Windows Messaging " & _
                                "Subsystem\Profiles"

                  Case 2   'NT
                      sKeyName = "Software\Microsoft\Windows NT\" & _
                                 "CurrentVersion\" & _
                                 "Windows Messaging Subsystem\Profiles"
               End Select

               sValueName = "DefaultProfile"
               sDefaultUserProfile = QueryValue(sKeyName, sValueName)
               objSession.Logon ProfileName:=sDefaultUserProfile, _
                                ShowDialog:=False
               Exit Sub
            Case Else
               MsgBox "An error has occured while attempting" & Chr(10) & _
               "To create and logon to a new CDO (1.x) session." & _
               Chr(10) & "Please report the following error to your " & _
               "System Administrator." &  Chr(10) & Chr(10) & _
               "Error Location: frmMain.StartMessagingAndLogon" & _
               Chr(10) & "Error Number: " & Err.Number & Chr(10) & _
               "Description: " & Err.Description
         End Select
      End Sub

If you know where to look in the registry on a Win9x system for the default email profile, please let me know!

Thanks,

Mark Phillips





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using vb6 to send email with attachment LeonMK Pro VB 6 3 August 25th, 2011 01:56 AM
CDO - MAPI - Email - AddressBook Access Question HyperVirus Pro Visual Basic 2005 0 November 1st, 2007 05:49 AM
Troubles with Programm AlisaSmi Excel VBA 0 March 7th, 2007 07:50 AM
Email using VB6 wehave74 Pro VB 6 2 January 6th, 2007 09:58 AM
DataGrid Troubles mrideout BOOK: Beginning ASP.NET 1.0 1 August 17th, 2004 11:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.