获取发件人电子邮件地

获取发件人电子邮件地

本文介绍了获取发件人电子邮件地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有WithEvents项目作为Outlook.Items 

Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
设置objNS = GetNamespace(MAPI)
设置Items = objNS。 GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)
如果item.Class = olMail然后
如果Left $(item。主题,29)=危险识别报告然后
Dim Msg As Outlook.MailItem
Dim NewForward As Outlook.MailItem
Dim myFolder As Outlook.MAPIFolder
Dim olApp As Outlook。应用程序
Dim olNS As Outlook.NameSpace

设置Msg = item
设置NewForward = Msg.Forward
设置olApp = Outlook.Application
设置olNS = olApp.GetNamespace(MAPI)

strSender =
strSenderName = Sender.GetExchangeUser()。PrimarySmtpAddress

如果itm.SenderEmailAddress =EX然后
设置objSender = itm.Sender
如果没有(objSender不是)然后
设置objExchUser = Sender.GetExchangeUser()
如果不是(objExchUser是没有)然后
strSender = objExchUser.PrimarySmtpAddress
如果
结束如果
Else
strSender = itm.SenderEmailAddress
如果

我收到一个编译/对象错误以下行:

  strSenderName = Sender.GetExchangeUser()。PrimarySmtpAddress 
pre>

发件人名称显示为空。



我如何提取发件人的电子邮件地址?

解决方案

最初在评论中回答


I have the following VBA code which is meant to send an automatic email when a specific subject is received.

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

I'm getting a compile/object error at the following line:

strSenderName = Sender.GetExchangeUser().PrimarySmtpAddress

the sender name comes up as "empty".

How I can extract the sender's email address?

解决方案

Originally answered in comments.

这篇关于获取发件人电子邮件地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 03:30