Reading Lotus Notes mailbox from C#

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.
stanfordaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
can you use POP3 to access your mailbox? I use http://www.lesnikowski.com/mail/Index.aspx to retreive emails from Exchange.
0
Bill-HansonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stanfordaAuthor Commented:
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
Bill-HansonCommented:
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
stanfordaAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.