Sending an e-mail from Excel using the server mailfile

petergms

New Member
Joined
Jun 16, 2010
Messages
4
I have some Excel VBA code (see fragment below) which tests the sending of an e-mail via Lotus Notes. This works fine when using a local replica of the mailfile, but not with the server mailfile:

Code:
Set oNotesSession = CreateObject("Notes.NotesSession")
sMailFile = oNotesSession.GetEnvironmentString("MailFile", True)
sMailServer = oNotesSession.GetEnvironmentString("MailServer", True)
'sTest is simply a string which selects the type of test I need to run
sTest = "Server, subdir not hardcoded"

If sTest = "Local, named" Then
    'Open a local replica of the mailfile using the mailfile name
    '*** This works ***
    Set oNotesDatabase = oNotesSession.GetDataBase("", sMailFile, False)
ElseIf sTest = "Local, unnamed" Then
    'Open a local replica of the mailfile without using the mailfile name
    '*** This works ***
    Set oNotesDatabase = oNotesSession.GetDataBase("", "", False)
ElseIf sTest = "Server, subdir not hardcoded" Then
    'Open the server mailfile using the server name and the mailfile name
    '*** This fails ***
    Set oNotesDatabase = oNotesSession.GetDataBase(sMailServer, _
        sMailFile, False)
ElseIf sTest = "Server, subdir hardcoded" Then
    'Open the server mailfile using the server name and the mailfile name
    'with the subdirectory hardcoded
    '*** This works ***
    Set oNotesDatabase = oNotesSession.GetDataBase(sMailServer, _
        "mail3\" & sMailFile, False)
End If

If oNotesDatabase.IsOpen = False Then oNotesDatabase.OPENMAIL
The problem is that my server mailfile is in a subdirectory on the server (mail3\petergms.nsf) - but I don't know how to programmatically extract the full path to get "mail3". In my code below, sMailFile = oNotesSession.GetEnvironmentString("MailFile", True) yields "petergms.nsf". When (and only when) I assign sTest to "Server, subdir not hardcoded", Set oNotesDatabase = oNotesSession.GetDataBase(sMailServer, sMailFile, False) yields Nothing, and the subsequent oNotesDatabase.IsOpen condition fails.

Hardcoding the subdirectory is not an option, as different users have their mailfiles in different subdirectories, and it is particularly a problem where users don't have local replicas. Is there any way of programmatically extracting the full path, or of bypassing this problem? (Forcing users to create local replicas won't be acceptable.)

-Peter
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top