Download Selected Attachments In Mail File

The following code will allow your users to more effectively manage their
attachments. We have found that in our organization, most of the used disk
space in mail files is due to attachments that users have forgotten to delete
in their mail file. This code will make it a lot easier for them by allowing
them to go to an attachments view, which displays only messages with
attachments (obviously) and allows them to select any number of messages and
click a button to delete all attachments from the messages.

You can customize the location where the attachments are stored, I chose c:\My
Documents\Notes Attachments

If a user downloads a file that already exists in that directory, it will ask
them if they want to overwrite the file, create a new file name with a number
appended to the filename (dismore.txt will be called dismore1.txt, if they
download it again it will be called dismore2.txt), or cancel the entire
operation.

In place of the attachments in the message, it tells them where the file was
downloaded to and what the file was called.
Create a view called "Attachments". This view is catagorized by date and shows
who sent the attachment, the subject of the message, and a column with the
following formula - @AttachmentNames + "=" +
@Text(@Round(@AttachmentLengths/1024)) + " Kb\'s" + " "

I also have a total MB column set to total with the following formula -
@Sum(@Round(@AttachmentLengths/1024000))

Create an action button in this view that calls the following agent..... I
called the agent (Download Attachments). The code for the action button is as
follows:

answer := @Prompt([YESNO]; "Download selected attachments?"; "Would you like to
download all attachments from the selected documents to the c:\\My
Documents\\Notes Attachments\\ directory on your computer?");
@If(answer = 1; @Command([ToolsRunMacro];"(Download Attachments)"); @Return(""))

The agent is setup like the following:


---Initialize Event---

Sub Initialize

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim answer As Integer
Dim rtitem As Variant
Dim attachname As String
Dim filename As String
Dim extension As String
Dim checkname As String
Dim newname As String
Dim x As Integer

On Error Resume Next
Mkdir "c:\My Documents"
Mkdir "c:\My Documents\Notes Attachments"

Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
x = 0

Do Until Doc Is Nothing
Set rtitem = doc.GetFirstItem( "Body" )

' Goes to the body field and finds all attachments
If ( rtitem.Type = RICHTEXT ) Then
Forall obj In rtitem.EmbeddedObjects
If ( obj.Type = EMBED_ATTACHMENT ) Then
' If a duplicate file name is found, ask the user
whether they would like to overwrite , update name, or cancel entire operation
If( Dir$("c:\My Documents\Notes Attachments\" &
obj.Source)) <> "" Then
attachname =
obj.source
answer = Msgbox ("This folder already contains a
file named " & attachname & ". " & Chr(10) & "Would you like to create a new
file name for this file in the format 'filenameX'? " & Chr(10) & Chr(10) & "If
you choose yes, a new file name will be created. " & Chr(10) & "If you choose
no, the file will be overwritten with this attachment. " & Chr(10) & "The
cancel button will stop the download process for the rest of the selected
documents." , 547, "Warning!" )

' 2= cancel, 7= No (overwrite), 6= Yes (update
name)
Else
attachname = obj.source
Call obj.ExtractFile( "c:\My Documents\Notes
Attachments\" & attachname )
Call obj.Remove
Call rtitem.AddNewLine( 2
)
Call rtitem.AppendText(( "Your file was
downloaded to c:\My Documents\Notes Attachments\ as filename: " ) & attachname)
Call doc.Save( False, True )
answer = 0
End If

If( answer = 2 ) Then ' User has chosen to cancel

Exit Sub

End If

If( answer = 7 ) Then ' User has chosen to overwrite
existing file

' Downloads file name and overwrites the
attachment with the same name
Call obj.ExtractFile( "c:\My Documents\Notes
Attachments\" & attachname )

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close