C# Outlook-查找邮件发送到的帐户的电子邮件
我的客户有问题,这意味着我有问题: 如果电子邮件收件人在Outlook中配置了多封电子邮件- 我有一个雅虎电子邮件帐户和两个来自不同Exchange服务器的Exchange帐户 在ProcessItemAdd事件处理程序(外接程序Express)中处理传入电子邮件时 我试图找出此电子邮件发送到3个帐户中的哪个帐户: 所以我的第一个方法是:C# Outlook-查找邮件发送到的帐户的电子邮件,c#,outlook,add-in,C#,Outlook,Add In,我的客户有问题,这意味着我有问题: 如果电子邮件收件人在Outlook中配置了多封电子邮件- 我有一个雅虎电子邮件帐户和两个来自不同Exchange服务器的Exchange帐户 在ProcessItemAdd事件处理程序(外接程序Express)中处理传入电子邮件时 我试图找出此电子邮件发送到3个帐户中的哪个帐户: 所以我的第一个方法是: Outlook.MailItem re = ((Outlook._MailItem)mail).Reply(
Outlook.MailItem re = ((Outlook._MailItem)mail).Reply();
if (re != null)
{
var thisEmail = "";
Outlook.Account account = re.SendUsingAccount;
if (account != null)
{
thisEmail = account.SmtpAddress;
Log.VerboseFormat("thisEmail = {0}", thisEmail);
Marshal.ReleaseComObject(re);
re = null;
Marshal.ReleaseComObject(account);
account = null;
if (String.IsNullOrEmpty(thisEmail))
{
// This requires that in the case of Exchange account it should be cached Exchange account.
thisEmail = (string)mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8580001F");
Log.VerboseFormat("Got receiver account email address from schema: {0}", thisEmail);
}
}
}
它在我的Outlook 2010 32位计算机上运行良好,但在我的Outlook 2010客户端计算机上不运行,返回空字符串。
因此,我的第二种(备份方法)是:
同样,这在我的机器上工作得很好,但在客户端机器上不工作,返回空字符串。
我确实验证了在我的客户端的情况下,发送方是带有缓存的Exchange帐户
顺便说一句,当发送方是非交换的,接收方是交换帐户时,它在客户端机器上运行良好
是否有任何其他方法可以可靠地确定电子邮件发送到哪个帐户(在多个收件人的情况下)
下面是我的最新代码,它在2010/2013年有效,但在2007年无效。后一个帐户上的值为空且x-header返回为空:
Outlook.MailItem re = ((Outlook._MailItem)mail).Reply();
if (re != null)
{
var thisEmail = "";
Outlook.Account account = re.SendUsingAccount;
if (account != null)
{
thisEmail = account.SmtpAddress;
Log.VerboseFormat("thisEmail = {0}", thisEmail);
Marshal.ReleaseComObject(re);
re = null;
Marshal.ReleaseComObject(account);
account = null;
if (String.IsNullOrEmpty(thisEmail))
{
string x_headers = (string)mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F");
thisEmail = FindTargetEmail(x_headers);
Log.Verbose("Extracted target email address from MIME x-headers: {0}", thisEmail);
}
}
else
{
Log.Verbose("account is null...");
if (String.IsNullOrEmpty(thisEmail))
{
string x_headers = (string)mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F");
thisEmail = FindTargetEmail(x_headers);
Log.Verbose("Extracted target email address from MIME x-headers: {0}", thisEmail);
}
}
编辑:
嗯,还没有结束。尽管它在我所有的机器上都能正常工作,但客户端在2010年报告了一个问题。这是一个非常奇怪的问题。
使用者user1@domain1.com(缓存的Exchange帐户)向用户发送电子邮件user2@domain2.com(gmail账户)。当我用上面的代码解析接收方端的MIME头,以获取此电子邮件发送到的地址时…我返回user1@domain1.com而不是user2@domain2.com !! 这怎么可能?我知道我正在解析标题的正确部分(是吗?)
专家们,有什么想法吗?通常Outlook配置文件中的a代表一个单独的帐户。您可以在每个存储中处理Items类(ADX术语中的ProcessItemAdd)事件,以标识电子邮件发送到的帐户。您是否尝试在客户端的计算机上调试它?是因为Account.SmtpAddress为空吗?或者因为MailItem.SendUsingAccount为空?您应该能够使用OutlookSpy查看对象,而无需安装任何调试工具-选择消息,在OutlookSpy工具栏上单击clicn项按钮,选择SendUsingAccount属性,单击Browse.AccountsMTAddress返回空字符串。正如我提到的,它在我的机器上工作,但在我客户的一些机器上AccountsMTAddress返回空字符串。使用PropertyAccessor的第二种方法也不返回任何内容…我的客户端不具备技术性,我无法开始安装OutlookSpy-除此之外,我没有;我没有…我正在尝试第三种也是最有希望的解析MIME x-header的方法。有问题的帐户是什么类型的?我相信这是Gmail帐户。同样在2007年,帐户返回null,x-header返回空。不幸的是,它不起作用…我有ProcessItemAdd,它传递的唯一参数是对象项,在我的例子中是Outlook.MailItem,从中可以找到文件夹:Outlook.MAPIFolder folder=FolderObj as Outlook.MAPIFolder;不幸的是,它不起作用…我有ProcessItemAdd,它传递的唯一参数是对象项,在我的例子中是Outlook.MailItem。从中可以找到文件夹:Outlook.MAPIFolder folder=FolderObj as Outlook.MAPIFolder;甚至store=folder.store;hoever商店没有邮件发送到的电子邮件地址-有时商店名称是电子邮件地址,但这不一定是电子邮件地址-可能只是文本…我的最新新闻-我介绍的代码在Outlook 2010/2013上运行良好,但在2007年不起作用-从PropertyAssessor返回的x_标头为空。。。