Manage Learn to apply best practices and optimize your operations.

Sendmailmemo Script

This is an improved version of a SendMailMemo script you may have seen here or
elsewhere. It allows you to pass in either an array or comma delimited string
for the recipients, A string or RT Body object, and allows you to change the
From or Principal field on the memo. Easy to use in UI or in Agents.
Function SendMailMemo(sendTo As Variant, cc As Variant, bcc As Variant, subject
As String, _
body As Variant, linkTo As NotesDocument, replyTo As String, principal As
String) As Integer
*******This Function acts something like @MailSend.*************
- Either pass in a comma delimeted string w/ the recipient names, or an array
containing the names
of the recipients for sendTo, CC, BCC...(empty string for any if there is none.)
- Subject simply accepts a string, and for the body field you can either pass
in a RichText Item or just a string.
- To include a doc link to a document pass a NotesDocument object as the 6th
parameter, if you don't wish to include
a doclink, then pass in "NOTHING". (The word, not an empty string)
- To set a ReplyTo field, include that as the 7th parameter as a string ...
empty string if there is no ReplyTo
- Last is the Principal parameter. This will make it appear in the recipients
Inbox to have come from whoever you specify. ( Good for Agents.)
NOTE: It will show in the memo that it was still sent by whover signed the
agent or called this function, but it is better than
showing being sent by the developer. To totally eliminate the developer/sender
from the mix, you'd have to create the maildoc in the
Mail.Box on the server. Search Lotus411 on how to do this.

On Error Goto ErrorHandler
Dim s As New notessession
Dim db As notesdatabase

Set db = s.currentdatabase

If db.IsOpen Then
Dim maildoc As NotesDocument
Dim rtItem As NotesRichTextItem
Set maildoc = db.CreateDocument

'check each recipient list for whether or not it is an array or a string.... (
I Explode the strings because send doesn't always work so well with just a
string )
If Not(Isarray(sendTo)) Then
MsendTo = Evaluate(|@Trim(@Explode('| & sendTo & |';','))|,
MsendTo = sendTo
End If
If Not(Isarray(cc)) Then
MCC = Evaluate(|@Trim(@Explode('| & cc & |';','))|, mailDoc)
MCC = cc
End If
If Not(Isarray(bcc)) Then
MBCC = Evaluate(|@Trim(@Explode('| & bcc & |';','))|, mailDoc)
MBCC = bcc
End If

'if a replyto person was passed in, then set it. Assuming just one person
string. If you need multiple, do as above fields...
If replyto<>"" Then maildoc.ReplyTo = replyto

If principal<>"" Then maildoc.Principal = principal
maildoc.SendTo = MsendTo
maildoc.CopyTo = MCC
maildoc.BlindCopyTo = MBCC
maildoc.Subject = subject

Set rtItem = maildoc.CreateRichTextItem("Body")
Call rtItem.AddNewLine(2)
Call rtItem.AppendText(body)
If Not(linkTo Is Nothing) Then
Call rtItem.AddNewLine(2)
Call rtItem.AppendText("Click to open document --> ")
Call rtItem.AppendDocLink(linkTo, "Click to open document")
End If

maildoc.PostedDate = Now()
maildoc.ComposedDate = Now()
maildoc.EncryptOnSend = False

Call maildoc.Send( False, False )

SendMailMemo = True
Print "Could not open database object"
Goto TheEnd
End If

Exit Function

Print ( "Error " & Str$(Err) & ": " & Error$ )
Resume TheEnd

SendMailMemo = False
End Function

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...