Link to home
Start Free TrialLog in
Avatar of melindaj
melindaj

asked on

how to access INBOX using perl

Is there any way That I can access INBOX or any other folder Example testfolder using PERL
to list subject and date and sender name, I have been able to access AllDocuments folder but not be able to access INBOX or testfolder, could you please guide how can I do this I have open question in PERL forum but I did not have any solution yet??
Avatar of RanjeetRain
RanjeetRain

I think you are trying to refer to Inbox folder as 'Inbox'. In fact, DOmino implements it as '($Inbox)'.

Try accessing ($Inbox) folder.
Ranjeet event All Documents internally refered as ($All) ?

melindaj, it is worth trying what Ranjeet proposed..

~Hemanth
What are you using to access Domino?  The PERL-to-COM library?  Or the PERL Domino library?  Please post a link to which library you downloaded for this, and teh code you were using that does work for All Documents, and the code you are using that fails for others.
Hemantha, I thought may be he used some demo code or something. In that case he could only be needed to know the correct name. Otherwise, we can always analyze, like Qwaletee said.
There is only one difference All Documents is a view and Inbox is a folder !
Avatar of melindaj

ASKER

Hi,
Thanx for reply,
I am accessing my data.nsf file from dos prompt using PERL script as bellow, it is working fine aslong as I am using $AllDocuments, but If I change $AllDocument to $Inbox or any other folder having problem the first problem I get
Can't call method "Count" on an undefined value at j5a.pl line 10.

use strict;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
    or die "Cannot start Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase('', 'data.nsf');
my $AllDocuments = $Database->AllDocuments;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";
for (my $Index = 1 ; $Index <= $Count ; ++$Index) {
    my $Document = $AllDocuments->GetNthDocument($Index);
      
    printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text};
    my $Values = $Document->GetItemValue('Index_Entries');
    foreach my $Value (@$Values) {
        print " Index: $Value\n";
    }
    last unless $Index < 5;
}
Try this:

use strict;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
   or die "Cannot start Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase('', 'data.nsf');
my $Inbox = $Database->GetView('($Inbox)');


Now $Inbox is ready for use.
Mind you, ($Inbox) is a folder, so the processing may be a little different.
my $AllDocuments = $Database->AllDocuments;

OK, fundamental misunderstanding of the Notes object model here.  $Database->AllDocuments means "take the OLD object represented by $Database, and retrieve its property named AllDocuments."  You thought AlDocuments represented the All Documents view, but it doesn't.  It is an unsorted NotesDocumentCollection that references every document in the database.

What you want is:

my $viewName = '($All)'
my $view = $Database->GetView($viewName)
my $AllDocuments = $view->AllEntries

Now, AllEntries is a NotesViewEntryCOllection (i.e., it contains the rows of the view, which REPRESENT documents but are not documnets themselves).  You were using AllDocuments before, which is a NotesDocumentCOllection.

So, where you have GetNthDocument, you need GetFIrstEntry and GetNthEntry

Also, since these return entries instead of documents, you can't use GetItemValue directly.  the easist change would be:

my $Values = $Document->Document->GetItemValue('Index_Entries');

Because a view netry -> DOcument returns the NotesDocument object that the view row represents.

Also, you use Lotus.NotesSession, which using the client UI to retrieve the objects.  You shoudl consider using Notes.NotesSession instead.  peration wll be identical but more efficient, except that you may have to initialize the session (password info).

Finally, GetNthENtry and GetNthDocument are very inefficient.  You shoudl use GetFirstEntry/GetENextEntry and GetFirstDocument/GetNextDOcument
What ever you say that is gun beyond me
I need help In coding
Thanx for explanation
here is the code that I have changed what is wrong with it now !! I want to list all my mail in INBOX !

use strict;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase('', 'jgolany.nsf');
my $viewName = '($All)';
my $view = $Database->GetView($viewName);
my $AllDocuments = $view->AllEntries;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";
for (my $Index = 1 ; $Index <= $Count ; ++$Index) {
    my $Document = $AllDocuments->GetNthDocument($Index);

    printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text};
my $Values = $Document->Document->GetItemValue('Index_Entries');

    foreach my $Value (@$Values) {
        print " Index: $Value\n";
    }
    last unless $Index < 5;
}
I have modified the script as per your recomendation I get the follwoing message

There are 895 documents in the database.
Can't use an undefined value as a HASH reference at jj3.pl line 13

my codes are
use strict;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase('', 'data.nsf');
my $viewName = '($All)';
my $view = $Database->GetView($viewName);
my $AllDocuments = $view->AllEntries;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";
for (my $Index = 1 ; $Index <= $Count ; ++$Index) {
my $Document = $AllDocuments->GetFIrstEntry($Index);
printf "$Index. %s\n", $Document->GetNthDocument('Subject')->{Text};
my $Values = $Document->Document->GetItemValue('Index_Entries');

foreach my $Value (@$Values) {
print " Index: $Value\n";
}
last unless $Index < 5;
}
Any one can Help
There is a flaw on how you are accessing entry object..

Try this code


use strict;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase('', 'data.nsf');
my $viewName = '($All)';
my $view = $Database->GetView($viewName);
my $AllDocuments = $view->AllEntries;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";

for (my $Index = 1 ; $Index <= $Count ; ++$Index) {
my $Document = $AllDocuments->GetNthEntry($Index)->Document;
printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text};
my $Values = $Document->GetItemValue('Index_Entries');

foreach my $Value (@$Values) {
print " Index: $Value\n";
}
last unless $Index < 5;
}

Hi Hamantha, qwaletee,
thanx for help but above code does as what my first code does,
I want to know how can I list of the mails in INBOX folder ??
at the beginning I miss understood the concept but thanks to qwaletee for explanation but still I do not know how can I access INBOX folder to list the mails. what do I need todo.
Hi Hamantha, qwaletee,
thanx for help but above code does as what my first code does,
I want to know how can I list of the mails in INBOX folder ??
at the beginning I miss understood the concept but thanks to qwaletee for explanation but still I do not know how can I access INBOX folder to list the mails. what do I need todo.
Replace this line

my $viewName = '($All)';

With

my $viewName = '($InBox)';

This will access inbox contents..
Yes this worked, using code above list the subject lines
1- I would like to include in my listing the Who column and Date line column correspond to subject line in from InBox what I need to do ?
2- How can I access other folders example I have Folder called "tony" ?


To access all other folder do the same as above.. replace the variable viewname accordingly

The who column is a field called From and Date is PostedDate, you have to use this two fields similar to the subject field in your perl script
Yes, thanks for Date and who filed tip that worked
But I am still unable to access other folders example "tony" I have replace from
my $viewName = '($InBox)'; TO my $viewName = '($tony)';
but I get error message " Can't call method "AllEntries" on an undefined value at jj6.pl line 9 "

Could you please help


Now it is not $Tony... It will be simply this

$viewName = "tony"

Inbox and AllDocuments view are mail system folders that is why they carry $ infront of them.

Yes thanks for all the help.
My last question is there any way I can open the body of the message if yes how
In the code provided we are opening 5 mail is there away to open the body of the message??
Will you atleast raise points now ??

To access body field.. use this

Body fields are different data type.. they are called RichText. So you will not get the exact format of the data, but only contents.

my $rtitem = $Document->GetFirstItem('Body');
my $rtText = $rtitem->GetFormattedText(0,0);

I have increased the points to 250
Thank you for this entire question, was answered very well,
Thank you again
ASKER CERTIFIED SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial