-
-
Save kubrick06010/3077752 to your computer and use it in GitHub Desktop.
Perl Win32::OLE Automation for Lotus Notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use diagnostics; | |
| use Win32::OLE; | |
| my $Notes = Win32::OLE->new('Notes.NotesSession')or die "$!: cannot st | |
| +art Lotus Notes Session object.\n"; | |
| my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); | |
| print "The current user is $Notes->{UserName}.\n"; | |
| print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n"; | |
| my $Database = $Notes->GetDatabase('', 'h:\$config\notes\davidapitest. | |
| +nsf') or die "$!: could not open database.\n"; | |
| if ($Database->IsOpen) | |
| { | |
| print "database is open\n"; | |
| } | |
| else | |
| { | |
| print "database is not open\n"; | |
| } | |
| print "creating new document\n"; | |
| my $Document = $Database->CreateDocument('test') or die "$!: can't cre | |
| +ate document"; | |
| if ($Document->IsNewNote) | |
| { | |
| print "document is new not saved\n"; | |
| } | |
| else | |
| { | |
| print "document is not new\n"; | |
| } | |
| print "populating fields\n"; | |
| $Document->{'plain_text'} = 'buffy'; | |
| $Document->{'SendTo'} = 'the'; | |
| $Document->{'Report'} = 'vampire slayer'; | |
| print "saving document\n"; | |
| $Document->Save (1, 1); | |
| $Document->Close; | |
| if ($Document->IsNewNote) | |
| { | |
| print "document is new not saved\n"; | |
| } | |
| else | |
| { | |
| print "document is not new\n"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use Win32::OLE; | |
| my $Notes = Win32::OLE->new('Notes.NotesSession') | |
| or die "Cannot start Lotus Notes Session object.\n"; | |
| my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); | |
| print "The current user is $Notes->{UserName}.\n"; | |
| print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n"; | |
| my $Database = $Notes->GetDatabase('', 'help4.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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my $Notes = Win32::OLE->new('Notes.NotesSession') or die "Cannot start Lotus | |
| Notes Session object.\n"; | |
| my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/); | |
| print "The current user is $Notes->{UserName}.\n"; | |
| print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n"; | |
| my $Database = $Notes->GetDatabase("", "mail2\HEYEBE.nsf") or die "Could not | |
| open database.\n"; | |
| $Database->OpenMail; | |
| my $AllDocuments = $Database->AllDocuments; | |
| my $Count = $AllDocuments->Count; | |
| print "Connected to ", $Database->{Title}, " on ", $Database->{Server}; | |
| print "There are $Count documents in the database.\n"; | |
| # scrappy code to test stuff | |
| # go to the FIRST folder | |
| $viewname = "FIRST"; | |
| my $view = $Database->GetView($viewname); | |
| # get first document and loop | |
| my $Doc = $view->GetFirstDocument; | |
| GetInfo_FromSubject($num, $Doc); | |
| $num = 0; | |
| while ($Doc = $view->GetNextDocument($Doc)) | |
| { | |
| $num++; | |
| GetInfo_FromSubject($num, $Doc); | |
| # try and delete / move email number 10 in this folder | |
| if ($num eq 10) | |
| { | |
| # so this one works | |
| #$Doc->Remove(1) or die ("Unable to remove\n"); | |
| # but these don't | |
| $Doc->PutInFolder("AAA", 1) or print ("Unable to PutInFolder: | |
| $!\n"); | |
| $Doc->PutInFolder("AAA") or print ("Unable to PutInFolder: | |
| $!\n"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment