Subject: @mailsend and web
Hi, Harold!
Here’s a valuable tool I wish I had earlier on in my career. Create an agent, which you’ll call from the WebQuerySave event of your form (assuming its a form). Then you paste in the code below under the ‘Initialize’ event of the LotusScript agent and call the code with the appropriate parameters included (very similar to the @mailsend). Let me know if you have problems:
Function Mailer(doc As NotesDocument, SendTo As Variant, CC As Variant, BCC As Variant, Subject As String, Body As String, AppendDocLink As Variant, AppendURLLink As Variant) As Variant
'LotusScript version of the @MailSend function
Dim NewLine As String
NewLine = Chr(13) + Chr(10)
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim URLLink As String
Dim db As notesdatabase
Set db = Doc.ParentDatabase
Set maildoc = New NotesDocument( db )
maildoc.Subject = Subject
Dim SendToArray
If Isarray(SendTo) = False Then 'If SendTo not array of names then convert to array
SendToArray = Explode(Cstr(SendTo), ",", False, False)
maildoc.SendTo = SendToArray
Else
maildoc.SendTo = SendTo
End If
Dim CopyToArray
If Isarray(CC) = False Then 'If SendTo not array of names then convert to array
CopyToArray = Explode(Cstr(CC), ",", False, False)
maildoc.CopyTp = CopyToArray
Else
maildoc.CopyTo = CC
End If
Dim BlindCopyToArray
If Isarray(BCC) = False Then 'If SendTo not array of names then convert to array
BlindCopyToArray = Explode(Cstr(BCC), ",", False, False)
maildoc.CopyTp = BlindCopyToArray
Else
maildoc.BlindCopyTo = BCC
End If
Set rtitem = maildoc.CreateRichTextItem( "Body" )
Call rtitem.AppendText( Body)
Call rtitem.AddNewLine( 3 )
If AppendDocLink = True Then
Call rtitem.AppendText( "(Please follow the link provided to view the document.)")
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendDocLink( doc, "Click here to open the document" )
End If
If AppendURLLink = True Then
If (AppendDocLink = True) Then
Call rtitem.AppendText( NewLine + NewLine + NewLine + NewLine )
End If
URLLink = "http://" + doc.Server_Name(0) + "/" + doc.DBPath(0) + "/0/" + doc.UniversalID + "?OpenDocument"
Call rtitem.AppendText( "Use the following URL to open the document in a browser:" + NewLine)
Call rtitem.AppendText(URLLink)
End If
Call maildoc.Send(False)
End Function
’ -AND-
Function Explode(ListString As String, Delimiter As String, AllowNulls As Variant, TrimEachItem As Variant) As Variant
On Error Goto ErrorHandler
Dim Array() As String
Dim ArrayItem As String
Redim Array(0) As String
Dim pos As Integer
Dim arraynum As Integer
arraynum = -1
Pos = Instr(1, ListString, Delimiter)
Do
If Pos > 0 Then
ArrayItem = Strleft(ListString, Delimiter)
ListString = Strright(ListString, Delimiter)
If TrimEachItem Then ArrayItem = Fulltrim(ArrayItem)
If AllowNulls = True Or ArrayItem <> "" Then
arraynum = arraynum + 1
Redim Preserve Array(arraynum) As String
Array(arraynum) = ArrayItem
End If
Else
arraynum = arraynum + 1
Redim Preserve Array(arraynum) As String
If TrimEachItem Then ListString = Fulltrim(ListString)
If AllowNulls = True Or ListString <> "" Then
Array(arraynum) = ListString
End If
ListString = ""
End If
Pos = Instr(1, ListString, Delimiter)
Loop Until Pos <= 0 And ListString = ""
Explode = Array
Exit Function
ErrorHandler:
Explode = Array
Exit Function
End Function