【发布时间】:2015-11-20 13:24:09
【问题描述】:
我正在使用插件 express 开发 Outlook 插件。当我收到发件箱邮件时,我可以在“mailItem.SenderEmailAddress”下看到我的电子邮件地址,格式为 x500。有没有办法将其转换为 SMTP 电子邮件地址。
这是我的代码:
Outlook.Explorer expl = null;
Outlook.Selection selection = null;
Outlook.MailItem mailItem = null;
Outlook.Recipient recipient = null;
string recipientsEmail = "";
try
{
expl = Globals.ObjOutlook.ActiveExplorer() as Outlook.Explorer; ;
if (expl != null)
{
selection = expl.Selection;
if (selection.Count == 1)
{
if (selection[1] is Outlook.MailItem)
{
mailItem = (selection[1] as Outlook.MailItem);
if (mailItem != null)
{
string senderEmailAddress = mailItem.SenderEmailAddress;
我的尝试和成功:- 我知道如何使用 Outlook.Recipient 对象将 x500 类型转换为 SMTP。在那里我可以获取收件人的“addressEntry”并获取 ExhangeUser,然后转到 ExhangeUser 的“PrimarySmtpAddress”。但我不确定如何处理 SenderEmailAddress 并将其转换为 SMTP。
一些有趣的实验 :- 由于“Sender”的属性在当前的 mailitem 对象中不可用,我设法使用反射来获取“Sender”的属性。但是当我运行以下代码时,“propertyInfo”对象值变为空。我不明白为什么。
这里是代码
//...
if (mailItem != null)
{
var mailItem2 = GetNewObject(mailItem, "Sender", intArray);
//...
public static object GetNewObject(Outlook.MailItem o, string popertyName, object[] parameters)
{
try
{
PropertyInfo propertyInfo = o.GetType().GetProperty(popertyName); // This object is getting null
return propertyInfo.GetType().GetProperty(popertyName).GetValue(o,parameters) as Outlook.MailItem;
}
catch (MissingMethodException ex)
{
// discard or do something
Debug.DebugMessage(2, "AddinModule : Error in GetNewObject() : " + ex.Message);
return null;
}
}
请给我建议。谢谢。
【问题讨论】:
-
由于您将问题标记为“Outlook-Redemption”,您是否正在寻找 Redemption 解决方案?
-
@DmitryStreblechenko,是的,我是。因为我总是乐于接受救赎。但是您对“PR_SENDER_ENTRYID”的评论完全解决了任何问题。非常感谢。
-
@DmitryStreblechenko:如果您对此感兴趣,请提交:stackoverflow.com/documentation/outlook-addin/commit
标签: c# reflection exchange-server outlook-addin outlook-redemption