Link to home
Start Free TrialLog in
Avatar of devo00
devo00Flag for United States of America

asked on

Read and Parse All Emails in a Lotus Notes Account

I need to be able to open a Lotus Notes account, cycle through and read data and attachments from all new emails in that account's inbox. How is this done in C#?
So far, I've managed to successfully get a count of messages in the account inbox:
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Domino;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
NotesSession session = new NotesSession();
session.Initialize("mypassword");
NotesDatabase db = session.GetDatabase("Server", "mailaccount", false);
NotesView mailView = db.GetView("($Inbox)");
msgCount = mailView.EntryCount;
label1.Text = mailView.EntryCount.ToString();
}
}
 
-Not sure how to continue.

Open in new window

Avatar of mbonaci
mbonaci
Flag of Croatia image

Here is an example of going through all view/folder's documents and all its fields:
//Code snippet for iterating through the views and fetching data
//
    NotesViewEntryCollection notesViewCollection = LotusNotesView.AllEntries;
    for( int rowCount = 1; rowCount <= notesViewCollection.Count; rowCount++ )
    {
        
        //Get the nth entry of the selected view according to the iteration.
        NotesViewEntry viewEntry = notesViewCollection.GetNthEntry( rowCount );
        //Get the first document of particular entry.
        NotesDocument document =  viewEntry.Document;    
            
        object documentItems = document.Items;  
        Array itemArray1 = (System.Array)documentItems;
        
        for( int itemCount=0 ; itemCount< itemArray1.Length; itemCount++ )
        {
            NotesItem notesItem = (Domino.NotesItem)itemArray1.GetValue( itemCount );
        
            //compare field value with specific value
            if( notesItem.Text !=null )   
            {
                if( (notesItem.Text.ToUpper()).StartsWith( "CONTACT" ))
                {
                    Contact contact = new Contact(); 
                    for( int icount=0 ; icount< itemArray1.Length; icount++ )
                    {
                        NotesItem searchedNotesItem = (Domino.NotesItem)itemArray1.GetValue( icount );
                        string FieldName = searchedNotesItem.Name.ToString();
                        //For FirstName
                        
                        if( searchedNotesItem.Name == "FirstName" ) 
                            contact.FirstName= searchedNotesItem.Text; 
                            
                        //For LastName
                        
                        if( searchedNotesItem.Name == "LastName" ) 
                            contact.LastName = searchedNotesItem.Text;     
                        //For Office Phone Number
                        
                        if( searchedNotesItem.Name == "OfficePhoneNumber" ) 
                            contact.OfficePhoneNumber = searchedNotesItem.Text;    
                        
                        if( searchedNotesItem.Name  == "InternetAddress" ) 
                            contact.EmailId = searchedNotesItem.Text; 
                    }//end for
                    contactsList.Add( contact );
                    break;
                }//End if
            }
        }
    }

Open in new window

Avatar of devo00

ASKER

This lets me access the contacts data, but I need to parse out data (body, subject, sender, etc) from emails themselves. Seems like an easy thing to do with the code above, I just don't know the sytax for Lotus objects.
 
Avatar of devo00

ASKER

Also, I get this error:
CS0246: The type or namespace name 'Contact' could not be found (are you missing a using directive or an assembly reference?)
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And forget Contacts, the code was just an example which used someone that had class Contacts defined somewhere...
Avatar of devo00

ASKER

Excellent resources given
Glad I could help :)