5

我正在使用以下代码读取来自 MS Outlook 2010 的传入邮件 -

public static void outLookApp_NewMailEx(string EntryIDCollection)
{                
    NameSpace _nameSpace;
    ApplicationClass _app;
    _app = new ApplicationClass();
    _nameSpace = _app.GetNamespace("MAPI");
    object o = _nameSpace.GetItemFromID(EntryIDCollection);
    MailItem Item = (MailItem)o;
    string HTMLbpdyTest = Item.HTMLBody;
    string CreationTime = Convert.ToString(Item.CreationTime);
    string strEmailSenderEmailId = Convert.ToString(Item.SenderEmailAddress);
    string strEmailSenderName = Item.SenderName;
    string Subject = Item.Subject;
} 

如何获取发件人的邮件 ID。我试过Item.SenderEmailAddress了,但它没有给我发件人的电子邮件 ID。它给了我这样的东西-

/O=EXG5/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=TEST35345
4

2 回答 2

6

现在返回的地址是一个 ( X.400 ) Exchange 地址。请查看这篇 MSDN 文章,了解如何检索相应的 SMTP 地址。

于 2013-05-31T12:21:33.337 回答
1

我正在使用这个 VBA 例程来检索对象的SMTP地址mailItem

(应该很容易移植到 C#)

Private Function getSmtpMailAddress(sMail As Outlook.mailItem) As String
    Dim strAddress As String
    Dim strEntryId As String
    Dim objRecipient As Outlook.Recipient
    Dim objSession As Outlook.NameSpace
    Dim objAddressentry As Outlook.AddressEntry
    Dim objExchangeUser As Outlook.ExchangeUser
    Dim objReply As Outlook.mailItem

    On Error GoTo ErrHandler

    If sMail.SenderEmailType = "SMTP" Then
        strAddress = sMail.SenderEmailAddress
    Else
        Set objReply = sMail.reply()
        Set objRecipient = objReply.recipients.item(1)

        strEntryId = objRecipient.EntryID

        objReply.Close OlInspectorClose.olDiscard

        Set objSession = getMapiSession

        strEntryId = objRecipient.EntryID

        Set objAddressentry = objSession.GetAddressEntryFromID(strEntryId)
        Set objExchangeUser = objAddressentry.GetExchangeUser()

        strAddress = objExchangeUser.PrimarySmtpAddress()
    End If

    getSmtpMailAddress = strAddress

    Exit Function

ErrHandler:
    Err.Clear
    On Error GoTo 0
    getSmtpMailAddress = "???"
End Function

这适用于Outlook 2007. MSDN 如上所述, Outlook 2010的解决方案看起来更好一些。

于 2013-05-31T13:06:56.287 回答