Solved

Reading Lotus Notes mailbox from C#

Posted on 2009-07-08
5
1,656 Views
Last Modified: 2013-12-18
We have a .NET windows application written in C#. We have a mail account set up in "Lotus Notes 6.5" for emails sent to our customer service department. I want to get the C# application to "read" the email that arrives in this mail box.

The reason is that we have some jobs that we wish to automate. For example, a customer might request us to resend a quote. In this instance the C# application will read the request and resend the quote, rather than having a customer service representative do it manually.
Thanks in advance.
0
Comment
Question by:stanforda
  • 2
  • 2
5 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24805681
can you use POP3 to access your mailbox? I use http://www.lesnikowski.com/mail/Index.aspx to retreive emails from Exchange.
0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 500 total points
ID: 24805743
No problem.

The first step is to make sure that Notes is installed on the computer that is running the code.

Next, add a reference to the "Lotus Domino Objects" library (on the COM tab).

Now, include the Domino reference in your source file:

    using Domino;

The only thing left is to read the records from the mail file.  Here's a basic example to get you started.  This example simply reads the mail found in the inbox folder.  If you need a more complex query, let me know.  You'll also want to change the mailServer and mailFile variables to point to your customer service email file rather than the current user's file.


            NotesSession sess = new NotesSession();

            sess.Initialize("");

            String mailServer = sess.GetEnvironmentString("MailServer", true);

            String mailFile = sess.GetEnvironmentString("MailFile", true);

            NotesDatabase db = sess.GetDatabase(mailServer, mailFile, false);

            NotesView inbox = db.GetView("($Inbox)");

            NotesDocument doc = inbox.GetFirstDocument();

            while (doc != null)

            {

                String subject = (string)((object[])doc.GetItemValue("Subject"))[0];

                String from = (string)((object[])doc.GetItemValue("From"))[0];

                String body = doc.GetFirstItem("Body").Text;

                doc = inbox.GetNextDocument(doc);

            }

Open in new window

0
 

Author Comment

by:stanforda
ID: 24978277
Thanks for the very quick responses. I had a couple of issues getting the client running on my dev machine as I normally run Notes in Citrix, but got the client working OK in the end.
 Just a couple of things.;
- I initially couldn't get the Session to start... then I realised I hadn't set the password...doh. Sorted that, so no worries.
- sess.GetDatabase always returned NULL no matter what I put into the Server and FileName. I went into the Notes Client and looked at the database properties and used the sames settings in the call... still no joy. Had a bit more of a dig around and found these;
                NotesDbDirectory dir = sess.GetDbDirectory("");
                NotesDatabase db = dir.OpenMailDatabase();
...did work OK, so that is good.
- Should there be some "tidy up" code to close the session when the application ends?

Cheers,
Andrew
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 24979339
RE: "sess.GetDatabase always returned NULL no matter what I put into the Server and FileName"

Probably due to the Citrix environment.  I've never seen this fail before.

RE: "Should there be some "tidy up" code to close the session when the application ends?"

I'm not sure if it makes a difference in C#, but I usually set my Domino objects to null when I'm done with them.
0
 

Author Comment

by:stanforda
ID: 24980105
I "normally" run Notes in Citrix, but to test this I ran locally... hence the need to configure the client on my local PC.

I'll just set my objects to null to finish. A lot of these type of objects (i.e. that consume network resources)  usually have at least a "dispose" method which would clean up any resources it was consuming. I guess the .Net Garbage Collector will tidy this up eventually if need be.

Very pleased to find a solution. Thanks for you help
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now