C# 是否有任何理由在不触发安全警报的情况下从Outlook帐户获取电子邮件地址?
我有一个outlook加载项,我必须在其中获取当前帐户的电子邮件地址,以使其正常工作。我使用简单的outlook应用程序,过滤现有的电子邮件,只获取公司的电子邮件IDC# 是否有任何理由在不触发安全警报的情况下从Outlook帐户获取电子邮件地址?,c#,outlook,add-in,C#,Outlook,Add In,我有一个outlook加载项,我必须在其中获取当前帐户的电子邮件地址,以使其正常工作。我使用简单的outlook应用程序,过滤现有的电子邮件,只获取公司的电子邮件ID public static string getOutlookEmail() { Outlook.Application myApp = new Outlook.Application(); Outlook.Accounts accounts = myApp.Session.Acco
public static string getOutlookEmail()
{
Outlook.Application myApp = new Outlook.Application();
Outlook.Accounts accounts = myApp.Session.Accounts;
int count = accounts.Count;
string mailID = null;
for (int i = 1; i <= count; i++)
{
if (ifCompanyAccount(accounts[i].SmtpAddress.ToString();))
{
mailID = (accounts[i].SmtpAddress.ToString());
i = count + 1;
return mailID;
}
else
{
return "No e-Mail";
}
}
}
public静态字符串getOutlookEmail()
{
Outlook.Application myApp=新建Outlook.Application();
Outlook.Accounts=myApp.Session.Accounts;
int count=accounts.count;
字符串mailID=null;
对于(int i=1;i如果您的代码在Outlook加载项中运行,则只要您使用传递给加载项的Outlook.Application
对象而不是创建新实例,它就不会成为安全提示的主题
不要在COM加载项中使用newnew Outlook.Application()
您还可以使用(从不显示安全提示)及其集合。我认为这解决了我的问题,首先我不能在this.Application.Session.CurrentUser.AddressEntr
但是我用了这种方式
Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
Outlook.Accounts accounts = explorer.Session.Accounts;
为了获得帐户信息,我基本上没有创建新的Outlook。应用程序正如Dmitry最初建议的那样谢谢Dmitry,我现在实际上无法使用赎回。但是关于传递Outlook对象,我已经这样做了,如果我在新的电子邮件实例上运行我的加载项,它会工作得很好(Application.Session.CurrentUser.AddressEntry),但我的实际外接程序将位于外部菜单中,例如(文件、主页…等),然后位于我的外接程序菜单中。我不知道如何使用当前对象获取当前帐户的电子邮件地址。你说的“外部菜单”是什么意思?您是指Explorer而不是Inspector?调用加载项回调的方式有什么区别?是的,我是指Explorer。例如,如果我使用Outlook.Explorer Explorer=this.Application.ActiveExplorer()。它将在(此)无效属性上出错。但在Inspector上似乎工作正常。因此,如果我无法使用(此)如何传递当前的Outlook.Application?我没有看到您的代码,因此我不知道这两种情况下“this”指的是什么类。我找到了这一行,Outlook.Explorer=Globals.ThisAddIn.Application.ActiveExplorer()。它与我一起工作