Sending an e-mail from an other user

If a user sends an e-mail using an agent, he seems to be the sender or the agent signer seems to be the sender if the agent is scheduled.
This is not always the desired behavior, especially in the case of scheduled agents in which the sender of the e-mail seems to be the developer of that agent or the administrator of the server.

You can customize the sender of the e-mail saving a document directly in the mail.box as the following example:

Option Public
Option Declare

Sub Initialize
	
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim dbMailBox As NotesDatabase
	Dim docMail As NotesDocument
	Dim item As NotesItem
	Dim rtitem As NotesRichTextItem
	Dim str_sendTo As String
	Dim str_copyTo As String
	Dim str_blindCopyTo As String
	Dim str_recipients As String
	Dim sendTo As Variant
	Dim copyTo As Variant
	Dim blindCopyTo As Variant
	Dim recipients As Variant

	Set db = s.Currentdatabase
	Set dbMailBox = New NotesDatabase(db.server, "mail.box")
	Set docMail = dbMailBox.Createdocument()		

	str_sendTo = "user1;user2;user3"	
	str_copyTo = "user4;user5;user6"	
	str_blindCopyTo = "user7;user8;user9"
	
	str_recipients = str_sendTo+";"+str_copyTo+";"+str_blindCopyTo
	
	sendTo = Split(str_sendTo, ";")
	copyTo = Split(str_copyTo, ";")
	blindCopyTo = Split(str_blindCopyTo, ";")
	recipients = FullTrim(Split(str_recipients, ";"))

	Call docMail.Replaceitemvalue("Form", "Memo")

	Set item = docMail.Replaceitemvalue("PostedDate", Now)
	
	Set item = docMail.Replaceitemvalue("From", "[sender]")
	Set item = docMail.Replaceitemvalue("INetFrom", "[sender]")
	Set item = docMail.Replaceitemvalue("Principal", "[sender]")	
	
	Set item = docMail.Replaceitemvalue("Recipients", recipients)
	Set item = docMail.Replaceitemvalue("SendTo", sendTo)
	Set item = docMail.Replaceitemvalue("CopyTo", copyTo)
	Set item = docMail.Replaceitemvalue("BlindCopyTo", blindCopyTo)
	
	Set item = docMail.Replaceitemvalue("Subject", "[subject of mail]")
	
	Set rtitem = docMail.CreateRichTextItem("Body")
	Call rtitem.Appendtext("[body of mail]")

	Call docMail.Save(True, False, False)
	
End Sub

In this example the variables of type Variant sendTo, copyTo, BlindCopyTo and recipients were obtained using the Split function on a string but you can directly use an array of strings or just a string in the case of a single recipient.
Often these fields are copied from another document:

Set item = itemOtherDocument.CopyItemToDocument(docMail, "sendTo")

Finally in the instructions:

Set item = docMail.Replaceitemvalue("From", "[sender]")
Set item =docMail.Replaceitemvalue("INetFrom", "[sender]")
Set item = docMail.Replaceitemvalue("Principal", "[sender]")

You can enter the sender of the e-mail.

This code was developed on Wndows 7 service pack 1 and Lotus Notes Designer 8.5.3 but works on older versions.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.