Create email message with a specific sender under IBM Domino

Normally, when an agent sends a message under Domino, the sender field is set to the signer of the Domino agent. There are tons of articles in the Internet about this topic, but I could not find a complete solution.

When you issue Document.send(), the „From“ field of the email message is overwritten with the agent signer. But if you use, all fields are left untouched. Here is a sample code snippet  to send a message:

public void sendMessage() throws Exception {

	// Variables
	lotus.domino.Session		notesSession	= null;
	lotus.domino.Database		notesDatabase	= null;
	lotus.domino.Document		notesDocument	= null;
	lotus.domino.RichTextItem	notesRTItem		= null;
	lotus.domino.DateTime		notesDateTime	= null;
	String						emailSender		= "";
	String						emailRecipient	= "";
	String						emailSubject	= "Message from the Domino server";
	String						emailBodyText	= "This is a sample body text";

	try {
		notesSession = NotesFactory.createSession();
		notesDatabase = notesSession.getDatabase(null, "");

		if (!notesDatabase.isOpen())
			throw new Exception("Unable to open the Domino router mail box");

		notesDocument = notesDatabase.createDocument();
		notesDocument.replaceItemValue("Form", "Memo");
		notesDocument.replaceItemValue("From", emailSender);
		notesDocument.replaceItemValue("SMTPOriginator", emailSender);
		notesDocument.replaceItemValue("Sender", emailSender);
		notesDocument.replaceItemValue("INetFrom", emailSender);
		notesDocument.replaceItemValue("Principal", emailSender + '@' + notesSession.getEnvironmentString("Domain", true));
		notesDocument.replaceItemValue("SendTo", emailRecipient);
		notesDocument.replaceItemValue("Subject", emailSubject);

		notesDateTime = getDominoSession().createDateTime("Today");
		notesDocument.replaceItemValue("PostedDate", notesDateTime);

		notesRTItem = notesDocument.createRichTextItem("Body");
		notesRTItem.appendText(emailBodyText);, false);

		} catch (NotesException e) {
			throw new Exception("Unable to send the message: " + e.text);
		} finally {
			try {
				if (notesDateTime != null)

				if (notesRTItem != null)

				if (notesDocument != null)

				if (notesDatabase != null)

				if (notesSession != null)
			} catch (NotesException e) {
				// Ignoring any object cleanup errors