Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam using ASP.NET 3.5. I want to read emails from MS outlook. I found this link which is very useful.

http://www.c-sharpcorner.com/uploadfile/rambab/outlookintegration10282006032802am/outlookintegration.aspx[^]

I have two issues.

1. Outlook's security access pops up a window asking for access. What do I need to configure & where to by-pass this window. The application will run as a web service automatically from a server and therefore this window wont look good.

2. The code I found allows me to access the default outlook account on my pc. What code do I write to access another email account. In other words, how do I pass the user account credentials to the outlook DLL that I am referring to.

Many thanks!
Posted
Updated 2-Dec-10 12:18pm
v2
Comments
Dalek Dave 2-Dec-10 18:19pm    
Minor Edit for Grammar.

XML
Outlook Interop dll has a recipient class where the email address of the user can be added.  Below is the code
<br>

<code>  Outlook.Application outlook = new Outlook.ApplicationClass();
        Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
        object _missing = Type.Missing;
        ns.Logon(_missing, _missing, false, false);
        
        Outlook.Recipient recipient = (Outlook.Recipient)   
        ns.CreateRecipient("email address");
        recipient.Resolve();
         
        Outlook.MAPIFolder inbox = ns.GetSharedDefaultFolder
        (recipient,Outlook.OlDefaultFolders.olFolderInbox);
        
        int unread = inbox.UnReadItemCount;
        foreach (Outlook.MailItem mail in inbox.Items)
        {
            string s = mail.Subject;
            string body = mail.Body;
        }        </code>

The code straight away accesses the emails. I think the domain user account, where the code runs, has to be an administrator account.
<br>
The permissions still keep coming. Iam currenly looking at the anti-virus programme to see anything can be configured here.</br></br>
 
Share this answer
 
I downloaded a dll from below website to overcome Outlook's security access issue.
http://www.mapilab.com/download/[^]
(under Advanced Security for Outlook)

I did not have to add the DLL to the ASP.NET project. I re-started my pc after the download.

The first time the application accessed outlook, I received a popup asking me to set security permission for the application accessing outlook. Once I set this up wth the correct option, Outlook's popup message never appeared.

No side issues so far.
 
Share this answer
 
v2
Comments
sujanir 5-Dec-10 16:03pm    
http://support.microsoft.com/kb/310244
This link has good info on codign with outlook Interop DLL. Grab it before Microsoft changes the link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900