Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

by ergowolf (Monk)
on May 01, 2000 at 01:43 UTC ( #9769=sourcecode: print w/ replies, xml ) Need Help??

Category: mail client
Author/Contact Info ergowolf
Description: This is a Lotus Notes client written in perl.
use strict;
use Win32::OLE;

my %count;
my $Buffer;
my $choice;
my $doc;
my $Document;
my %noteshash = ();
my $num;
my $userid = "x";
my $search;
my $server = "x/x";
my $val;
my $VERSION = '1.0';

my $Notes = Win32::OLE->new('Notes.NotesSession')or die "Cannot start 
+Lotus Notes Session object.\n";
my $Database = $Notes->GetDatabase("$server", "mail\$userid.nsf") or d
+ie "Could not open database.\n";
my $AllDocuments = $Database->AllDocuments;
my $Count = $AllDocuments->Count;
my @counted = (1 .. $Count);

print "\n\nPlease wait while the notes mail file is processed . . .\n\
foreach $doc (@counted) {
        $Document = $AllDocuments->GetNthDocument($doc);
        $val = sprintf "$doc. %s", $Document->GetFirstItem('Subject')-

while ($choice ne "Q"){
print "\n\nWelcome to the Perl Notes client.\n";
print "Press I to look at an index of email.\n";
print "Press B to look at the body of a message.\n";
print "Press Q to exit the program.\n";
chomp($choice = <STDIN>);
$choice =~ tr/a-z/A-Z/;

        if ($choice eq "I") {

        if ($choice eq "B") {
        if ($choice eq "Q") {

sub idex {
my $docnum;

print "What is the first number you would like to see? ";
chomp($docnum = <STDIN>);

my $limit = $docnum + 5;
        for ($docnum; $docnum < $limit; $docnum++) {
        print "Number: $doc Subject: $noteshash{$docnum}\n";
sub body {
print "What document would you like to look at? ";
chomp($doc = <STDIN>);
$Document = $AllDocuments->GetNthDocument($doc);
my @Attributes = $Buffer->info();
printf "\n\n$doc. %s\n", $Document->GetFirstItem('Body')->{Text};

=head1 NAME

getnotes - This script gets all the documents in a notes database and 
+prints out a document by number.


This is my first attempt at accessing notes databases from perl.  I ca
+n think of some interesting uses for notes and perl.
I would specifically like to pull an email and compare it with a list 
+from another file.  This script is still in beta.

=head1 README

This script gets all the documents in a notes database and prints out 
+a document by number.


This script has a few requirements.  You will need the Win32::OLE modu
You will also need to change the values for nsf and server.








Comment on
Download Code
Replies are listed 'Best First'.
by buckaduck (Chaplain) on Jul 09, 2001 at 18:05 UTC
    For those having trouble:

    When accessing my email in Lotus Notes (which is what I presume the others are trying to do), I simply use an empty string for the server and the nsf. After accessing the database object, I call the OpenMail method:

    my $Database = $Notes->GetDatabase("", "") or die "Could not open database.\n"; $Database->OpenMail;


      Might want to replace $val = sprintf "$doc. %s", $Document->GetFirstItem('Subject')->{Text}; with: my $tempsub = $Document->GetFirstItem('Subject'); if ( defined($tempsub)) { $tempsub = $tempsub->{Text}; } else { $tempsub = "No Subject"; } $val = sprintf "$doc. %s", $tempsub; or something equivalent. Stops it knackering when some uncultured swine sends you an email with no subject title.
by diotalevi (Canon) on Dec 07, 2004 at 23:41 UTC

    The preceding has a few minor bugs and overall, isn't terribly useful as programs go. See Notes::OLE - Lotus Domino via Win32::OLE for an actual Domino developer's take on Win32::OLE access to Lotus Domino.

    my $Database = $Notes->GetDatabase( ... ) or die ...

    This will never fail. If the database does not exist then the database will not be opened and the $Database->{'IsOpen'} property will be false. Test that instead. Someone else already noted that "mail\$userid.nsf" is incorrect and either "mail\\$userid.nsf" or better, $Database->OpenMail() should be used.

    $AllDocuments->GetNthDocument( ... )

    This is known to be a wastefully expensive way to access a Document in a DocumentCollection. Instead of getting documents by number, use an iterator:

    my $doc = $AllDocuments->GetFirstDocument; while ( $doc ) { ... $doc = $AllDocuments->GetNextDocument( $doc ); }
      I can't seem to get the attachments. any help here?
by Anonymous Monk on Jan 12, 2001 at 13:20 UTC
    Any way to get to the attachments in the e-mail? I can see that the attachments are there but can't get at the data
by Thomas (Initiate) on May 23, 2000 at 15:24 UTC
    >my $AllDocuments = $Database->AllDocuments; This line fails for me, it doesn't seem like I have any problems connecting to the notes database though. Is there a place with some docs on which functions I can use on the $Database object?
      same problem here. Did you gain any insights since then?
      I don't know if this is answered already but when you try and open a database the code uses: mail\$userid.nsf In actuallity it should be this: mail\\$userid.nsf double back slashes. You won't get an error that the database is not opened unless you tried to open a view via the database property. Thanks, Yoofi:
by t'mo (Pilgrim) on Jan 05, 2001 at 22:23 UTC

    Any updates?

Back to Code Catacombs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://9769]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2015-10-04 12:14 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (102 votes), past polls