• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

DocumenContext fails

Hi,
I am trying to capture the contents of a mail. SO I have created an agent(shared agent) (After new mail has arrived).
But after debugging I have found that :
     Set doc = session.DocumentContext
     Ifrom = doc.from(0) ----> fails ??? Any reason
I have tried an alternate ways bu still fails :
Set it = doc.GetFirstItem("Subject")
but it also fails.
Here is the detail code :
-----------
Sub Initialize
     Dim session As NotesSession
     Set session = New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument
     Dim dbug As NotesLog
     Dim rtitem As Variant
     Dim fileCount As Integer
     Dim it As NotesItem
     Dim user As String
'     REM get the incoming mail message
     Set doc = session.documentcontext
'REM Specify the size limit for attachments
     Const MaxSize = 0
     fileCount = 0
     Set dbug = New NotesLog("Router log")
     dbug.LogActions = True
     dbug.OpenAgentLog
     dbug.LogAction("begin")
     
     
     Open "c:\\umapada" & FileName & ".txt" For Output As #1
'REM Log the subject name of the message for debug purposes
     user = session.CommonUserName
     Set doc = session.DocumentContext
     Ifrom = doc.from(0)   ' this  fails  ..any reason
     dbug.LogAction("umapada" )
     Set it = doc.GetFirstItem("Subject")
     Write #1, "Subject "
     Write #1,it.Text
     Write#1,"****************************************************************************"
     dbug.LogAction("doc subject from context" + "-> " + it.Text)
     Set rtitem = doc.GetFirstItem( "Body" )
     Write #1, "Body"
     Write #1, rtitem.Text
     Write #1,"****************************************************************************"
     dbug.LogAction("Mail preprocessing agent is done")
     dbug.Close
End Sub



-----------

Any comment will be highly appreciated.

thanks in advance,
umapada
0
umapada
Asked:
umapada
  • 6
  • 4
  • 3
  • +2
2 Solutions
 
ZvonkoSystems architectCommented:
You get a DocumentCollection with new mail documents.

Try something like this:

Sub Initialize
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim dc As NotesDocumentCollection
     Dim doc As NotesDocument
     Set db = session.CurrentDatabase
     Set dc = db.UnprocessedDocuments
     Set doc = dc.GetFirstDocument
     Do While Not (doc Is Nothing)
          Print "Subject: " & doc.Subject(0)
          Set doc = dc.GetNextDocument(doc)
     Loop
End Sub

0
 
snocrossCommented:
What do you mean by 'it fails'?  When you step through in debug mode and you reach that line of code what happens?  Does the code stop working and display an error or do you just find that the IForm value appears to be null?
0
 
snocrossCommented:
... I meant 'IFrom' by the way....
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
scottrmaCommented:
The DocumentContext property does not always return a valid handle in (After New Mail Arrives) agents. This is because there may be multiple mails that get delivered before amgr actually queues the agent to run. Therefore, it is better to use session.CurrentDatabase.UnprocessedDocuments and loop through this collection, as in Zvonko's example above, with this type of agent (even though there may be only one document in the collection). DocumentContext is still useful in (Before New Mail Arrives) agents, among other things.

Regards,

Scott
0
 
ArunkumarCommented:
Hey Zvo-Bro & Sno-Bro !

Yet again I excelled in stealing from my bro!

Sorry buddy...I could not resist it.

;-)
0
 
snocrossCommented:
Arun, not sure of which question you are refering to.
0
 
ZvonkoSystems architectCommented:
He is hoping to get this one :-)
0
 
ZvonkoSystems architectCommented:
Sh!t Thief!!!
He managed again to steal 100 of mines and 100 of Heman's points!!!

Ok ok, congrats' Bro :-)

0
 
snocrossCommented:
I'm confused.
0
 
ArunkumarCommented:
Look at the previously answered question.  The title of the question says "Points for Zvonko" LOL !!!

I didn't try to steal Hemans points by the way...

:-)
0
 
ZvonkoSystems architectCommented:
So it's special honor to be stolen by Bro!

Thanks, I will do you the same :-)

0
 
ArunkumarCommented:
As you see i am no longer actively participating here at EE.  Even if you steal it will be an honor for me !
0
 
ZvonkoSystems architectCommented:
Yes, I see, and I am sad about it Bro, really.
Just few days ago I got my cable modem and flat rate. Now we could chat anytime here. Instead of chatting I have to answer questions like this one! Why do I not get my email document here and not there and so on. And he is not even interested in his/her question. Afterwards he/she grades a B and says "thanks" :(
0
 
umapadaAuthor Commented:
Thanks scottrma ,
 I have got ur points.


regards,
umapada
0
 
ZvonkoSystems architectCommented:
...or he/she even don't talk to you :-)

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now