【问题标题】:Outlook VBA Mailitem property SenderEmailAddress not returning address correctlyOutlook VBA Mailitem 属性 SenderEmailAddress 未正确返回地址
【发布时间】:2014-11-03 00:02:15
【问题描述】:

所以我有一个程序可以让用户选择一个 Outlook 文件夹以导入到表中。然后可以从组合框中选择它并传输到表单中以供使用。

但是,我返回的值之一有问题。 SenderEmailAddress 实际上并没有给我一个电子邮件地址,例如这是我保存在我的表中的地址。

出于隐私考虑,我删除了姓名。

/O=COMPANY/OU=MAIL12/CN=RECIPIENTS/CN=FIRSTNAME.LASTNAME

当然,如果我想将此值传递回 Outlook 以回复电子邮件,我不能使用它。

有人可以帮帮我吗?

Public Sub LoadEmails()

    On Error Resume Next

    'Outlook wasn't running, start it from code
    If Started = False Then
        Set olApp = New Outlook.Application '("Outlook.Application")
        Started = True
    End If

    Set myNamespace = olApp.GetNamespace("MAPI")
    Set objFolder = myNamespace.PickFolder

    ' if outlook is closed, it will display this error
    If Err <> 0 Then
        MsgBox "Outlook was closed. Please log out and log back in."
        Started = False
        Exit Sub
    End If

    'Exit if no folder picked.
    If (objFolder Is Nothing) Then
        MsgBox "No Folder Selected"
        Started = False
        Exit Sub
    End If

    Dim adoRS As Recordset
    Dim intCounter As Integer
    Set adoRS = CurrentDb.OpenRecordset("TBL_UserInbox") 'Open table Inbox

    'Cycle through selected folder.
    For intCounter = objFolder.Items.Count To 1 Step -1
        With objFolder.Items(intCounter)
        'Copy property value to corresponding fields
            If .Class = olMail Then
                adoRS.AddNew
                adoRS("Subject") = .Subject
                adoRS("TimeReceived") = .ReceivedTime
                adoRS("Body") = .Body
                adoRS("FromName") = .SenderEmailAddress '<<<  Issue
                adoRS("ToName") = .To
                adoRS.Update
            End If
        End With
    Next

    MsgBox "Completed"

    Started = False
End Sub

【问题讨论】:

标签: vba email ms-access outlook


【解决方案1】:

这是一个完全有效的 EX 类型的电子邮件地址(与 SMTP 相对)。检查 MailItem.SenderEmailType 属性。如果是“SMTP”,请使用 SenderEmailAddress 属性。如果是“EX”,请使用 MailItem.Sender.GetExchangeUser.PrimarySmtpAddress。准备好处理空值/异常。

【讨论】:

  • 感谢您的帮助
猜你喜欢
  • 2013-06-08
  • 1970-01-01
  • 2013-06-01
  • 2018-11-20
  • 1970-01-01
  • 2021-03-12
  • 2015-12-06
  • 1970-01-01
  • 2016-09-09
相关资源
最近更新 更多