1

I'm writing a program where I can send mails (using domino.dll) from three different department mailboxes (each using its own mail server and nsf-file). All three department mailboxes have a predefined mail signature such as

Regards Department X

Since those can change anytime I don't want to hardcode the signature in my program but extract them from the mailbox/nsf-file instead and append it to the mail body (or something else if there are better approaches).

I've been looking around all day without finding a solution to this problem, so my question is: How is this achieved?

So far my code is similar to this:

public Boolean sendNotesMail(String messageText)
    {
        //Create new notes session 
        NotesSession _notesSession = new NotesSession();
        //Initialize Notes Database to null; 
        NotesDatabase _notesDataBase = null;
        //Initialize Notes Document to null; 
        NotesDocument _notesDocument = null;

        string mailServer = @"Path/DDB";
        string mailFile = @"Deparmentmail\number.nsf";

        //required for send, since its byRef and not byVal, gets set later. 
        object oItemValue = null;

        // Start the connection to Notes. Otherwise log the error and return false
        try
        {
            //Initialize Notes Session 
            _notesSession.Initialize("");
        }
        catch
        {
           //Log
        }

        // Set database from the mailServer and mailFile
        _notesDataBase = _notesSession.GetDatabase(mailServer, mailFile, false);

        //If the database is not already open then open it. 
        if (!_notesDataBase.IsOpen)
        {
            _notesDataBase.Open();
        }

        //Create the notes document 
        _notesDocument = _notesDataBase.CreateDocument();

        //Set document type 
        _notesDocument.ReplaceItemValue("Form", "Memo");

        //sent notes memo fields (To and Subject) 
        _notesDocument.ReplaceItemValue("SendTo", emailAddress);
        _notesDocument.ReplaceItemValue("Subject", subjectText);
        // Needed in order to send from a departmental mailbox
        _notesDocument.ReplaceItemValue("Principal", _notesDataBase.Title);

        //Set the body of the email. This allows you to use the appendtext 
        NotesRichTextItem _richTextItem = _notesDocument.CreateRichTextItem("Body");

        // Insert the text to the body 
        _richTextItem.AppendText(messageText);
        try
        {
            _notesDocument.Send(false, ref oItemValue);
        }

}

EDIT: Thanks to Richard Schwartz my solution is:

object signature = _notesDataBase.GetProfileDocument("calendarprofile", "").GetItemValue("Signature");
String[] stringArray = ((IEnumerable)signature).Cast<object>().Select(x => x.ToString()).ToArray();
_richTextItem.AppendText(stringArray[0]);
ThoBa
  • 505
  • 4
  • 8

2 Answers2

3

The signature is stored in a profile document in the NSF file. You can use the method NotesDatabase.getProfileDocument() to access it. This method takes two arguments:

ProfileName: The profile document name that you need to find the signature is "calendarprofile". (Yes, that's right. It's actually a common profile for many functions, but the calendar developers got there first and named it. ;-))

UniqueKey: Leave this as an empty string. (It is traditionally used to store a username in profile documents in shared databases, but not used in the calendarprofile doc in the mail file.)

You access data in the profile document the same way that you access them in regular documents, e.g., using getItem(), getItemValue(), etc. For a simple text signature, the NotesItem that you are looking for is called "Signature". I notice, however, that there are also items called "Signature_1" and "Signature_2", and "SignatureOption".

If you look at the Preferences UI for setting signatures in Notes mail, you will see that there is a choice between simple text and HTML or graphic files. No doubt this choice will be reflected in the SignatureOption item, so you will probably want to check that first. I have not explored where the data goes if you use imported HTML or graphic files, so I can't say for sure whether it goes into Signature, Signature_1, Signature_2, or somewhere else. But you can explore that on your own by using NotesPeek. You can download it here. It presents a tree-style view of the NSF file. There's a branch of the tree for Profiles, and you can find the calendarprofile there. Then just play around with different settings in the Notes mail preferences and see what changes. (NotesPeek doesn't pick up changes on the fly. You have to close and re-open the profile in NotesPeek after saving changes in the Notes mail preferences dialog in order to see the changes.)

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • Thanks alot. This works (after a little workaround with the returned object) and I now have a working solution. – ThoBa Jan 14 '13 at 11:12
0

If this gets too difficult, and you want a standard solution for all mails, you might consider this product or a similar one.

D.Bugger
  • 2,300
  • 15
  • 19