[英]Get sender email address
我有以下 VBA 代碼,用於在收到特定主題時發送自動電子郵件。
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
If item.Class = olMail Then
If Left$(item.Subject, 29) = "Hazard Identification Report" Then
Dim Msg As Outlook.MailItem
Dim NewForward As Outlook.MailItem
Dim myFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Set Msg = item
Set NewForward = Msg.Forward
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
strSender = ""
strSenderName = Sender.GetExchangeUser().PrimarySmtpAddress
If itm.SenderEmailAddress = "EX" Then
Set objSender = itm.Sender
If Not (objSender Is Nothing) Then
Set objExchUser = Sender.GetExchangeUser()
If Not (objExchUser Is Nothing) Then
strSender = objExchUser.PrimarySmtpAddress
End If
End If
Else
strSender = itm.SenderEmailAddress
End If
我在以下行收到編譯/對象錯誤:
strSenderName = Sender.GetExchangeUser().PrimarySmtpAddress
發件人姓名顯示為“空”。
如何提取發件人的電子郵件地址?
最初在評論中回答。
為什么不是 msg.SenderEmailAddress
以上接受的答案對我不起作用。 相反,我正在使用它(也適用於 MeetingItems):
Function GetSenderEmail(oM As Variant)
Dim oPA As Outlook.PropertyAccessor
Set oPA = oM.PropertyAccessor
GetSenderEmail = oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
End Function
感謝 David Lee 在此線程中提供的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.