Lotusscript: Mail Notification Class
Back in August 2009, I posted a small class I had created to make it easier for me to create mail notifications in my Lotusscript agents. Since then I have improved on it, and I wanted to post the latest version. One recent feature I added is to send external mail to the internet that looks like it is coming from a different user. This is often needed when you have an agent signed with a developer/admin ID, but you want the mail to look like it is coming from a particular department or user. This is done by using the (unsupported) method of saving the document in mail.box instead of using doc.Send() to mail it directly. What I found is that you should use mail.box on the same server as the agent is running on, you can not access mail.box on a different server. The code reflect this. Other new features are support for doclinks, attachments and an option to display a warning message at the end that the mail comes from an un-monitored role account. This warning is actually turn on by default. Here is an example of how to use the class: Option Public Option Declare Use "Class.MailNotification" Sub Initialize Dim mail As NotesMail ' *** Create a mail Set mail = New NotesMail() ' Set receipient and subject mail.MailTo = "texasswede@example.com" Call mail.AddMailTo("texasswede2@example.com") mail.Subject = "Please Read This" mail.Principal = "bogus_user@example.com" ' Create body Call mail.AppendText("Testing email...") Call mail.AppendNewLine(2) Call mail.Send() End Sub And here is the class itself. Enjoy! Option Public Option Declare Class NotesMail Public maildoc As NotesDocument Public body As NotesRichTextItem Private p_subject As String Private p_sendto List As String Private p_copyto List As String Private p_blindcopyto List As String Private p_principal As String Public NoReply As Integer Public mailbox As NotesDatabase Public Sub New() Dim session As New NotesSession Dim mailservername As String mailservername = session.Currentdatabase.Server ' Using mail.box directly is unsupported, but is the ' only way to make the mail look like it is actually ' sent from another address, in our case the principal. Set mailbox = New NotesDatabase(mailservername,"mail.box") If mailbox.Isopen = False Then Print "mail.box on " & mailservername & " could not be opened" Exit Sub End If Set me.maildoc = New NotesDocument(mailbox) Call me.maildoc.ReplaceItemValue("Form","Memo") Set me.body = New NotesRichTextItem(maildoc,"Body") me.p_subject = "" me.p_principal = "" ' Empty lists for addresses Erase me.p_sendto Erase me.p_copyto Erase me.p_blindcopyto me.NoReply = False ' Default is to add a disclaimer to the end End Sub Public Property Set Subject As String me.p_subject = FullTrim(Subject) End Property Public Property Get Subject As String Subject = me.p_subject End Property Public Property Set Principal As String me.p_principal = FullTrim(Principal) End Property Public Property Get Principal As String Principal = me.p_principal End Property '*** Recipient address (mailto) functions *** Public Property Set MailTo As String me.p_sendto(FullTrim(MailTo)) = FullTrim(MailTo) End Property Public Property Get MailTo As String ' Get the first address only ForAll mto In me.p_sendto MailTo = mto Exit ForAll End ForAll End Property Public Property Set SendTo As…