OK, I have put together an agent to forward mail, it is supposed to remove any large attachment and include some data.
When run manually in the UI it works perfect, however when set to run "Before mail arrives" it only forwards mail without any attachments...
The code:
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim forward As NotesDocument
Dim forwardaddress As String
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim atta As String
Dim remo As String
' **** set to the address that you would like to forward mail to, maxsize of attachements ****
forwardaddress = "mine@outside.com"
Const MaxSize = 3000000
Set db = s.currentdatabase
Set doc = s.DocumentContext
Set forward = New NotesDocument(db)
Call doc.CopyAllItems(forward, True)
Set rtitem = forward.GetFirstItem( "Body" )
'determine if any attachment exist, remove them if they are to big
atta = "no attachments included"
remo = ""
If Not Isempty (rtitem.EmbeddedObjects) Then
atta = ""
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) And (o.FileSize > MaxSize) Then
remo = "removed attachment: "
atta = atta + o.source + ", "
Call o.Remove
Call forward.Save(True,True)
End If
End Forall
End If
'navigation element in order to place header in front of body text
Set rtnav = rtitem.CreateNavigator
Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)
'print recipients into the new mail heading
Call rtitem.BeginInsert(rtnav)
'all kinds of data inserted here as texts
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo")
Call forward.RemoveItem("BlindCopyTo")
forward.Send False, forwardaddress
Call forward.RemovePermanently(True)
End Sub
Can someone please solve this?
I have also tried to set the agent to run "after new mail has arrived" on all new mail messages but then nothing gets forwarded...
Discuss This Question: 1  Reply