Solved

Reading Lotus Notes mailbox from C#

Posted on 2009-07-08
5
1,917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 70

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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