Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting default e-mail profile 1

Status
Not open for further replies.

bmoyer23

MIS
Dec 5, 2001
46
US
We are using the MAPI to email via a VB6 application. When using this method you have to provide a valid mail profile if you want to bypass the profile dialog. We have PCs setup with different default mail profile names(ie: "ms exchange settings", "outlook", ...). Is there a way (maybe via reading the registry) to get the user's default mail profile? Thanks in advance.
 
Exactly how are you using MAPI?

if you are using the actual API, then, from the documentation:

[when calling MAPILogonEx]
Select the default profile by passing NULL in the lpszProfileName parameter and setting the MAPI_EXPLICIT_PROFILE flag

 
I use CDO to resolve user names... Is that what you meant? Here is some sample code.
[tt]
Public Function CDOResolveUser(ByVal MailUser As String) As String
On Error GoTo ErrorHandler
Dim myName As String
myName = "CDOResolveUser(MailUser=" & MailUser & ")"

Dim objOutbox As Folder
Dim objNewMessage As Message
Dim objRecipients As Recipients
Dim objOneRecip As Recipient

If Not IsNull(objSession) Then
CDOResolveUser = Val(ConnectToMailbox(strLoginName))
If Val(CDOResolveUser) = 1000 Then GoTo ErrorHandler
End If

Set objOutbox = objSession.Outbox
Set objNewMessage = objOutbox.Messages.Add
Set objRecipients = objNewMessage.Recipients
Set objOneRecip = objRecipients.Add
With objOneRecip
.Name = MailUser
.Type = ActMsgTo
.Resolve showdialog:=False ' Get MAPI to determine complete E-mail address.
End With

CDOResolveUser = objOneRecip.Name

Set objOutbox = Nothing
Set objNewMessage = Nothing
Set objRecipients = Nothing
Set objOneRecip = Nothing

Exit Function
ErrorHandler:
Set objOutbox = Nothing
Set objNewMessage = Nothing
Set objRecipients = Nothing
Set objOneRecip = Nothing
CDOResolveUser = MailUser ' reset to what it was

End Function
[/tt]

Craig, mailto:sander@cogeco.ca

In the computer industry, there are three kinds of lies:
lies, damn lies, and benchmarks.
 
oops sorry you might need this too.
[tt]
Private Function ConnectToMailbox(ByVal strLoginName As String) As Long
On Error GoTo ErrorHandler

Set objSession = CreateObject("mapi.session")
objSession.Logon "", "", False, False, 0

Exit Function
ErrorHandler:
Set objSession = Nothing
End Function
[/tt]

Craig, mailto:sander@cogeco.ca

In the computer industry, there are three kinds of lies:
lies, damn lies, and benchmarks.
 
strongm: Thanks for the post. I am using the CDO reference (ie: CreateObject("mapi.session")). What is the preferred method in your opinion? I haven't seen to many examples accessing the API directly.

Craig: Thanks for your example. Worked great when testing on a local pc. But we are also running Citrx... doesn't seem to work there.
 
The default profile can be read from the registry and passed to the Logon method thereby avoiding the MAPI logon dialog appearing. Its location depends on the Windows platform:

95/98/ME
HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles

NT/2000/XP
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles

In both cases the value name that holds the data is DefaultProfile. The above applies equally to the MAPISession control and CDO 1.21.

Paul Bent
Northwind IT Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top