I have tried to access and read the outlook mail. I have tried following code but it gives me an security warning popup by saying "A program is trying to access e-mail address information stored in outlook express." when I try to access Microsoft.Office.Interop.Outlook.MailItem in the foreach.
const string OUTLOOK_PROCESSNAME = "OUTLOOK";
const string OUTLOOK_APPLICATIONNAME = "Outlook.Application";
private static Microsoft.Office.Interop.Outlook.Application StartOutlookApplication()
{
return StartApplication(OUTLOOK_PROCESSNAME, OUTLOOK_APPLICATIONNAME) as Microsoft.Office.Interop.Outlook.Application;
}
private static object StartApplication(string processName, string applicationName)
{
// Application object
object app = null;
try
{
// is there an existing application object ?
if (Process.GetProcessesByName(processName).Length > 0)
{
// use the GetActiveObject method to attach an existing application object
app = Marshal.GetActiveObject(applicationName);
}
if (app == null)
{
// create a new instance
Type t = Type.GetTypeFromProgID(applicationName);
app = Activator.CreateInstance(t);
}
}
catch (System.Exception ex)
{
// Some Logging
Trace.WriteLine(string.Format("Error while starting the Application: {0}", applicationName));
}
return app;
}
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
Microsoft.Office.Interop.Outlook.Application app = StartOutlookApplication();
Microsoft.Office.Interop.Outlook.NameSpace NS = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
lastupdateddate = getmostrecentupdatetime();
DateTime lastupdated=Co开发者_JS百科nvert.ToDateTime(lastupdateddate);
subFolder = inboxFld.Folders[Inboxpath];
foreach (Microsoft.Office.Interop.Outlook.MailItem t in subFolder.Items)
{
if (t.SenderEmailAddress.Contains(senderemail))
{
Please some one help me.I need to run my program without showing this warning message.
The redemption library will get around most of them. http://www.dimastr.com/redemption/
精彩评论