我试图访问并阅读Outlook邮件。我尝试了下面的代码,但是它通过说“程序试图访问存储在outlook express中的电子邮件地址信息”给我一个安全警告弹出窗口。当我尝试在foreach中访问Microsoft.Office.Interop.Outlook.MailItem时。
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=Convert.ToDateTime(lastupdateddate);
subFolder = inboxFld.Folders[Inboxpath];
foreach (Microsoft.Office.Interop.Outlook.MailItem t in subFolder.Items)
{
if (t.SenderEmailAddress.Contains(senderemail))
{
请有人帮助我。我需要运行我的程序而不显示此警告消息。