We help IT Professionals succeed at work.

File not found when creating attachment through LotusScript in a scheduled agent

Jean Marie Geeraerts
on
I have an agent that creates a mail document and attaches a file that is stored on a network drive.
When I run the agent manually everything works fine, but when the agent is scheduled I always get a file not found error.

I know when the agent is scheduled it is executed on the server with the server's id, so I have check if the file is available on the server and even tried to map a drive on the server where the agent is run, but still no result. I alway get a file not found error.

Here' the script I use :
Sub Initialize
      REM ===========================================================================
      REM Global declarations
      REM ===========================================================================
      Dim session As notessession
      Dim agent As notesagent
      Dim db As notesdatabase
      Dim agentLog As noteslog
      Const LogFile$="logs/agents.nsf"
      Dim LogServer As String
      
      REM ========================================================================
      REM Initialize session and variables
      REM ========================================================================
      Set session = New NotesSession
      Set agent=session.currentagent
      Set db=session.CurrentDatabase
      LogServer=db.Server
      
      REM ========================================================================
      REM open agentlog and define error routine
      REM ========================================================================
      Set agentLog = New NotesLog(db.Title + " - " + agent.name)
      Call agentLog.OpenNotesLog(LogServer$, LogFile$)
      Call agentLog.LogAction("Agent started")
      On Error Goto LogError
      
      REM ========================================================================
      REM Local variables
      REM ========================================================================
      Dim parametersView As NotesView
      Dim parameterDoc As NotesDocument
      Dim mailDoc As NotesDocument
      Dim mailBody, mailText As NotesRichtextItem
      Dim attachment As NotesEmbeddedObject
      
      REM ========================================================================
      REM Loop through parameter documents
      REM ========================================================================
      Set parametersView=db.GetView("Parameters")
      Set parameterDoc=parametersView.GetFirstDocument
      Do While Not (parameterDoc Is Nothing)
            ' Create mail document
            Set mailDoc=db.CreateDocument
            mailDoc.Form="mailForm"
            ' set subject
            mailDoc.Subject=parameterDoc.MailSubject(0)
            ' get text from parameterDoc
            Set mailText=parameterDoc.GetFirstItem("MailText")
            Set mailBody=mailDoc.Createrichtextitem("Body")
            If mailText.Text<>"" Then
                  Call mailBody.AppendRtItem(mailText)
            End If
            ' create attachment
            Set attachment = mailBody.Embedobject(EMBED_ATTACHMENT, "", parameterDoc.FilePath(0))
            ' send document if attachment is created successful
            If Not (attachment Is Nothing) Then
                  Call mailDoc.Send(True, parameterDoc.MailTo(0))
            Else
                  Call agentLog.LogError(4000, "Attachment not found : " & parameterDoc.FilePath(0))
            End If
            ' get next document
            Set parameterDoc=parametersView.GetNextDocument(parameterDoc)      
      Loop
      
      REM ========================================================================
      REM close agent log and leave sub
      REM ========================================================================
      Call agentLog.LogAction("Agent finished")
      Call agentLog.close
      Exit Sub
      
      REM ========================================================================
      REM Error routine : logs an error and resumes on the next line
      REM ========================================================================
LogError:
      Call agentLog.logerror(Err, "Initialize: " + Error$ + " in line " + Cstr(Erl))
      Resume Next
End Sub

The script reads all parameter documents and gets the file path from that document. I've tried putting the file path as \\SERVERNAME\NETWORKRESOURCE\FILENAME.EXT or as D:\FILENAME.EXT where D is a mapped drive on the server with the currently logged on user. (there's always an administrator that is logged on on the server)

Does anybody have any idea why this won't work?
Comment
Watch Question

Commented:
Hello JM,

write another agent piping only the responses from shell command: NET USE
You will see that none mappings are in the list.
The reason is that Domino started as service does use SYSTEM as userid. This one is an internal account and can not be tested (or persistent mapped to a network drive).

I have solved this dilemma by doing a NET USE check, and after desired drive not found, mapped a drive on the fly in my agent (with: NET USE).

I am just now still at home. If I manage to find my old sources (it was only a test beside a bunch of others :-) I will paste it here or send as attachment in our mail list :-9

So long,
zvonko

PS: dedicating an userid for the Domino server is an bad idea (only not to waste your time with this :-)

:-)
Jean Marie GeeraertsApplication Engineer

Author

Commented:
How about when I use a network reference, without creating a mapping to the drive ?
I use the full network name of the file \\SERVER\RESOURCE\PATH and still can't locate the file.
So, I think it might be that the system user isn't allowed to access the file server where the file is stored.

The user that is logged on, is not dedicated for the domino server. It's a local administrator account logged on for backup-purposes. (Don't ask me why and how, I don't maintain the servers at operating system level, I only need to worry about domino administration).

I'll be in a meeting this afternoon, so I probably won't be able to test stuff until monday.
This is an extract from Lotus Site

This problem may occur if Domino is run as a Service on Windows NT and the NTFS permissions are inappropriately set on the drive(s) in question. In order to correctly recognize the drives and subdirectories, the SYSTEM user account needs have full access to the root of the drive as well as any subdirectories Notes needs access to (such as notesprogram, notesdata, WINNT, WINNT\System32, WINNT\System, etc.).

By default, NTFS permissions designate "Everyone" with "Full Control". If security concerns warrant a change, then the SYSTEM user may need to be specifically listed. To do this, perform the following steps:

1. Right-click the file or directory to secure and choose Properties.

2. Select the Security tab and choose Permissions.

3. In the File/Directory Permissions dialog box, select Add.

4. By choosing the Show Users option in the Add Users and Groups dialog box, the SYSTEM user becomes available. Select this user, making sure to allow Full Control.

5. Click OK three (3) times to back out of all dialog boxes.

6. If prompted to apply the setting to all subdirectories and files, it is a good idea to accept this box as it will ensure that all subdirectories also allow the SYSTEM access to them as well.


Try it out.

~Hemanth

Commented:
Sorry JM,

my tests does not help you :-)

I tested it as a web for with a button calling this agent:
Sub Initialize
 Dim session As New NotesSession
 Dim doc As NotesDocument
 Dim FileName As String
 Dim FileNum As Integer
 Dim InputLine As String
 
 On Error Goto errormessage
 
 Set doc = session.DocumentContext    
 FileName = "\\mchh2x3a\ablage\test.txt"
 FileNum = Freefile()
 
 Open FileName For Input As FileNum
 Line Input #FileNum, InputLine
 Close #FileNum
 
 doc.InputLine = InputLine & "<<"
 
 Exit Sub
 
errormessage:
 doc.InputLine = InputLine & "<<error>> in line: " & Erl
 Exit Sub
 
End Sub

In web, I got always error in line #14
In client I could observe correct fetching of file content.
Hemanth's hint had not helped on my side.
With or without SYSTEM user, agent running on server can not access this file shares.

Hope your tests bring more results.

zvonko
JM, I don't know if you have tried my solution. But here are few discussion topics that I tumbled across when I was searching for some problems that I had during odbc, runonserver. So here are some leads for you.

http://notes.net/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/58f1c8b43168942285256ad200318702?OpenDocument

Also these...

http://notes.net/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/818380e69dcc42b98525699800051a5a?OpenDocument

http://notes.net/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/8125c8be7f9ddac0852569d60024cb2e?OpenDocument

I am very sure the problem is due to access issue of system.

~Hemanth

Commented:
Hello JM,

this links from Heman does say that for Notes guys this problem still does not have an adequate solution.
My former solution (as I can now remember) was also a solution mixed from LotusScript using shell executing NT commands.
But today I remembered that a first example when Microsoft presented WSH was how to map network drives. So I searched again and here what I found as first link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmind99/html/adminWSH.asp

I mean this is a sign :-) I will make and test a super trooper LotusScript drive share relocator for Domino server using WSH COM
(And publish afterwards the solution on SandBox, so you do not need to increase the points :-)
Jean Marie GeeraertsApplication Engineer

Author

Commented:
Okay, if you post it on the sandbox, post a link here and I'll gladly up the points anyway ;-)
In the meantime, I'll see if I can get the user to transfer the file to a local drive on the server so it's available locally. In that case it should work.

Commented:
I think something was misleading in my post :-)
I will hurry to develop this as soon as possible for YOU!
The problem is I can do this only in the office.
The part with the SandBox was more a joke :-)
Jean Marie GeeraertsApplication Engineer

Author

Commented:
Okay, thanks anyway :-)
Jean Marie GeeraertsApplication Engineer

Author

Commented:
Hey zvonko,
I've used a workaround for this problem at the moment by running the script from a dedicated notes workstation with a client running locally scheduled agents.
I use the same client to transfer mails from my local server to the company's mail server. I can't use the default notes mechanism, since I'm not allowed to create a cross-certificate for the servers. I have therefore bypassed this by allowing users from the other domain on my local domain and creating a user with sufficient access on both domains to perform this.

Anyway I'm still interested in your super-deluxe resource locator :-)

Commented:
sorry JM that I loose this a bit from my observation :-)
I am back on this...
Jean Marie GeeraertsApplication Engineer

Author

Commented:
No hurry, as said I managed to bypass the problem, so take your time ;-)

Commented:
Hi JM, I forgot totally this one :(

...but lately a had to answer similar question. Does this answer help you too?
http://www.experts-exchange.com/Applications/Email/Lotus_Notes/Q_20336246.html

Almost 6 months of inactivity and here comes our Zvonko !

:-)
Arun.

Commented:
I have to collect all possible points to jump in front of you before 100K ;)

uh Oh... I thought you quit the race with me and let me win.

;-P
Arun.

Hi Jerrith, how about exchanging a 500 with Grade "A" ???
I will give you first and you can repay me later. What do you say ? Deal ?

Hi Bro!

Commented:
No, no, no!
No dirty tricks Bro!

But JM, could you please increase this points for an old friend :)

Jean Marie GeeraertsApplication Engineer

Author

Commented:
Don't have the time at the moment to really look at this, but looks like a possible solution. I'll have to try it out some time and will let you know.
I see you're begging for 500 points again :-)

Commented:
Who? Me! Never!!! ...but when you insist on it, then I have to take it :-)

Whatever...if you give my brother then make sure that you give me too.  I will repay you okay ?

;-P
Jean Marie GeeraertsApplication Engineer

Author

Commented:
Will I have to post a zillion comments to get those points?
You got it !!!  Shall we start one more for you jerrith ?

Commented:
No! no! no!
By doing so does our ranking list become a joke :(

Guess I need our AgentMulder during this period or a question like how to reveal hidden design ....

Couple more questions and I retire...Once I retire my rank wont be a joke right ?

;-P

Commented:
Arun, here is my picture about all that what we are doing here.
We do this all for our fun, right?
This is not the only side with this Q/A scenario. There are even exact copies of EE under other names. There are even sides where you get money for question answered. In this other systems you do not get direct relation between expert ranking and points because the site provider decides what is worthy for him and not the questioner. For example they want you to replay fast and often.

And this is the point: we are all searching for truth. Therefore are all systems which can not be manipulative attractive to us, like physics, mathematic and EE ranking lists. But when you can manipulate the system, then is the game no more interesting.

Please do not disturb my universe, please :-)
Jean Marie GeeraertsApplication Engineer

Author

Commented:
May the force be with you, Luke :-)
I'll thus just leave this question at 100 too...

Commented:
In Yugoslavia was a saying to the question: what do you like to get when your neighbor get the same twice? After a period of thinkingwas the answer: a big hole :-)

in India it goes like this...

what do you like to get when your neighbor get the same twice? After a period of thinking was the answer: loose one eye

Commented:
OK, now I know why we are called IndoGermans :-)
ZvonkoSystems architect
BRONZE EXPERT
Top Expert 2006

Commented:
Hello my dear fellows. How should we proceed here?
Jean Marie GeeraertsApplication Engineer

Author

Commented:
I have no idea. I'm no longer working on the problem since I've switched jobs since then.
I don't even remember if any of the links posted was a viable solution to the problem, but I did implement a workaround apparently :-)

Maybe, we just delete the question and forget about it? What do you think guys?
i'm also willing to up the question to 500 points ans split evenly with all, but I don't think the question is of much use to anyone else, so maybe we'd best delete it?
Systems architect
BRONZE EXPERT
Top Expert 2006
Commented:
I think we can simplify this and split points betwean Hean and my former upper account in upper reference to directory mapping feature.
That directory mapping feature was a regular Domino feature and I have tested und used it.
Anyway, there are not much detailed descriptions on the net how to enable that feature, so let us keep it here.

Please split points betwean Hemanth's comment http:#10811692 and this description:
========================================================
The way is a native Domino server directory mapping feature. To activate it you have to add three documents to your server’s names.nsf
Do it this way:
1.) Open server’s names.nsf
2.) Go to: Server\Servers and make the black border around your server’s row.
3.) In the ViewActions bar above the server list is the ActionIcon: Web…-> CreateURLMappingRedirection
4.) This action opens a new document where you should read: "MAPING/REDIRECTION for yourServer/yourOrg"
5.) Go in this document to the tab "Mapping" and enter this values:
Incoming URL string: /estar/*
Target server directory: X:\teams\implementation\deployment\estar link\*
6.) Save and Close this document.
7.) You are again in your Servers view. Select now the ViewAction: Web…->CreateFileProtection
8.) In the Basics tab enter this:
Path: C:\teams\implementation\deployment\estar link
9.) Switch to AccessControl tab and press the button: SetModifyACL
10.) Mark the first entry in the list so the value "-Default-" is visible in Name field.
11.) Click on "WriteReadExecute" radio button.
12.) Important! Click on the "NEXT" button.
13.) Save and close this second web document.
14.) Create a Program document for this server with this values:
Program name: cmd.exe
Command line: /C "net use x: \\127.0.0.1\CSC topsecret /USER:zvonko /PERSISTENT:YES"
Server to run on: yourServer/yourOrg
Enabled/disabled: STARTUP ONLY
15.) Restart your server.

If you have not make any typos and you have http log enabled, then you should read such lines in your access.log:
127.0.0.1 reflector.world.net - [20/Aug/2002:20:42:19 -0100] "GET /estar/eMedNYout.xls HTTP/1.1" 200 13824 "" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"

And this should be same, whether from Internet Explorer or in Notes client after pressing CTRL-L and entering the URL:
http://reflector.world.net/estar/eMedNYout.xls


Jean Marie GeeraertsApplication Engineer

Author

Commented:
OK. Consider it done.
ZvonkoSystems architect
BRONZE EXPERT
Top Expert 2006

Commented:
Thanks JM.

See you,
Zvonko
Jean Marie GeeraertsApplication Engineer

Author

Commented:
You're welcome. Thought an increase in points was due too, since it was complicated enough.
ZvonkoSystems architect
BRONZE EXPERT
Top Expert 2006

Commented:
Oh yea! I just noticed you did not accept the little zvonko's comment, but the big one :)