Hi this agent will deatch file when new mail will arrived.
Some points to this agent:
1) This will override the file if same file name will exist.
2) If there are two mail having the same file name will only export the last mail file.
(If you want to export all attachment, attachment name should be different)
3) In agent prooerties in second tab chek Allow for restricted Operation.
4) This agent will deatch file in servers C drive's Deatch Folder
5) If you will manually trigger this agent then it will deatch file on the same system C drive's deatch folder as path given
Deatch Agent Code:
Declaration:-
Dim session As NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Initialize:-
Sub Initialize
Set session = New NotesSession
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
If doc.HasEmbedded Then
Call detach( doc )
End If
Next
End Sub
Deatch Function:-
Sub detach( doc As NotesDocument )
Dim rtitem As Variant
Set rtitem = doc.GetFirstItem( "Body" )
Forall items In rtitem.EmbeddedObjects
If items.Type = EMBED_ATTACHMENT Then
Call items.ExtractFile( "C:\Detach\" & items.Source )
End If
End Forall
End Sub
Subscribe to:
Post Comments (Atom)
Thanks for the code. If any new developers see this you might want to be aware of a couple of things:
ReplyDelete1) Never ever use getNthDocument if you can avoid it. Use getNextDocument
2) Store the value of collection.count into a variable and reference the variable.
3) Avoid hard-coding paths as your script will fail if the path does not exist (you can check to see if the path exists using Dir). Instead, get a handle to the notes directory from domino itself.