Extract Values from Mail file - Agent Need Help?

Hi All,

I am trying to extract Reply to, Subject and Body of mail documents in the mail database.

I want to write these data into a csv file.

I have done following agent which works fine to a ceratin extent and I need your expertice advise to resolve few issues please.

  1. I want to run this agent aganist the Inbox view of the mail database, What would be the View name of the Inbox ?

  2. How can I modify the below agent only to work against the selected documents? ( user can select needed ones by clicking at them )

  3. Below Agent works fine with the From and Subject fields, but when I try to extarct Body by adding Cstr(Doc.Body(0)) to the write command it gives the error as " Variant does not contain a container"

Appreciate if someone can help to resolve these issues please.


Sub Initialize

Dim S As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim Doc As NotesDocument

Dim filenum As Integer



Set db = S.CurrentDatabase

Set view = db.GetView("ALL")

Set Doc = View.GetFirstDocument

filenum% = Freefile()

Open "E:\Angela\Mail.csv" For Output As filenum%

While Not (Doc Is Nothing )

Write #filenum%, Cstr(Doc.From(0)) , Doc.subject(0)

Set Doc = View.GetNextDocument(doc)

Wend

Close filenum%

End Sub

Subject: Extract Values from Mail file - Agent Need Help??

Hi Mira,

you need to set the agent to “Run against selected documents” then it will run to whatever you have selected in whatever folder/view (Inbox is ($Inbox) ). Body is a RichText Field so you have to deal with that.

Your export anyhow will fail!!! You can make a very save guess, that email messages contain newlines, commands etc. Therefore a CVS file is not a suitable export format. Also a mail might contain Mime that needs special treatment. You should consider DXL for Export to an XML format (CSV is soo last century)…

And please: ALLWAYS use Option Declare

However, here is the code:

Sub Initialize

Dim S As New NotesSession

Dim db As NotesDatabase

Dim dCol As NotesDocumentCollection

Dim rt As NotesRichTextItem

Dim Doc As NotesDocument

Dim filenum As Integer

Dim msg As String



On Error Goto Err_Export



Set db = S.CurrentDatabase

filenum = Freefile()

Open "E:\Angela\Mail.csv" For Output As filenum

Set dCol = db.UnprocessedDocuments

Set doc = dcol.GetFirstDocument



Do Until doc Is Nothing

	Set rt = doc.GetFirstItem("Body")

	msg = rt.GetUnformattedText 'You must process that since " and , and linebreaks will be in there

	Write #filenum, Doc.from(0), Doc.subject(0), msg

Loop

Exit_Export:

On Error Resume Next

Close filenum 'Force close

Exit Sub

Err_Export:

Msgbox Error$

Resume Next 'Replace with Exit_Export if you want to abort

End Sub

Hth

:slight_smile: stw

Subject: RE: Extract Values from Mail file - Agent Need Help??

Hi Stephan,

This is regarding exporting mail docs in xml format, instead of .csv.

  1. To be able to run the lotusscript classes for XML (or rather DXL), is it necessary that the code is executed from IE…or it can be run both from Notes and IE.

2)Could you please post some link and/or reading material on writing such code/agent (exporting data in to xml files)

Thanks a lot in advance

Puneet