Q
Problem solve Get help with specific problems with your technologies, process and projects.

Automatically save attachments to network drive

I have a mail-in database that receives e-mail with attachments. We need these attachments automatically saved...

to a network drive. I've found some code that will detach the file and save it to the network and document where it saved it to, but this only works when run from the client manually. I need an agent that will run on the server either on all new documents that will detach the file to the network drive.

Here's the code I've used to do it manually. How can this be tweaked to run from the server on a scheduled basis? If I use the code as is, in an agent set to run on a schedule, it does not run.

Sub Initialize 
        Dim session As New NotesSession 
        Dim db As NotesDatabase 
        Dim doc As NotesDocument 
        Dim dc As NotesDocumentCollection 
        Dim rtitem As Variant 
        Dim attachname As String 
        Dim filename As String 
        Dim body As NotesRichTextItem 
        Dim emphasize As NotesRichTextStyle 
        
        Set db = session.CurrentDatabase 
        Set dc = db.UnprocessedDocuments 
        Set doc = dc.GetFirstDocument 
        Set rtitem = doc.GetFirstItem( "Body" ) 
        
        If ( rtitem.Type = RICHTEXT ) Then 
Forall obj In rtitem.EmbeddedObjects 
If ( obj.Type = EMBED_ATTACHMENT ) Then 
Set emphasize = session.CreateRichTextStyle 
emphasize.Bold = True 
emphasize.NotesColor = COLOR_RED 
Set body = doc.GetFirstItem("Body") 
Call rtitem.AddNewLine( 2 ) 
Call body.AppendStyle(emphasize)         
attachname = obj.source 
Call obj.ExtractFile
( "\\
QDSWJDE1AMstarUnProcessed\" 
& attachname ) 
                                
Call rtitem.AddNewLine( 2 ) 
Call rtitem.AppendText(( "Your file was 
downloaded to\
\QDSWJDE1AMstarUnProcessed 
as filename: " ) & 
attachname) 
Call doc.Save( False, True ) 
                                
                        End If 
                End Forall 
        End If 
End Sub

This same code should work on the server (provided the filepath you specify is a valid path for the server -- I'm guessing this is a Windows server). You forgot to mention in what way this agent fails, but I assume that you're getting a "Not authorized to perform this operation" message.

Writing to the file system is a "restricted" operation, and for your agent to be able to do it, two things must be true. First, the ID that signed the agent must have access to run restricted agents. This is set in security tab of the server configuration document in the server's names.nsf. Second, the agent properties must have a "runtime security level" set to 2 or 3 -- the default is 1, which does not allow restricted functions.

One other consideration: it may be necessary to map the drive on the server so that you can specify the path using a drive letter (or, more generally for other server platforms, as a filepath that appears to be local).


Do you have comments on this Ask the Expert question and response? Let us know.

Dig Deeper on Lotus Notes Domino Agents

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

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