Again, you will get errors trying to instantiate a MAPI.Session if CDO 1.21
is not installed. It's optional and often is not installed.
There are many examples of various logons using CDO 1.21 at
www.cdolive.com/cdo5.htm.
A piggy-back logon won't do you any good at all if Outlook isn't running.
Here's an example of that:
Dim oCDO As MAPI.Session
Set oCDO = CreateObject("MAPI.Session")
oCDO.Logon "", "", False, False
For a logon using profile information you will need to know the mailbox and
server names and have a Windows logon with permissions on that mailbox. Then
you can use something like this:
Dim oCDO As MAPI.Session
Dim strProfileInfo As String
Set oCDO = CreateObject("MAPI.Session")
strProfileInfo = "<Your Servername>" & vbLf & "<Your Mailbox>"
oCDO.Logon "", "", False, True, 0, False, strProfileInfo
Or you can use the profile name if you know it:
oCDO.Logon "<Profile Name>", "", False, True, 0
Profile names can be found under HKCU\Software\Microsoft\Windows
NT\CurrentVersion\Windows Messaging Subsystem\Profiles. The default profile
is listed in a string value in that key named DefaultProfile.