【问题标题】:list / get all SentOnBehalfNames in outlook列出/获取 Outlook 中的所有 SentOnBehalfofName
【发布时间】:2023-04-08 03:06:01
【问题描述】:

我有一个创建新电子邮件的宏,代表发送......但我不想明确使用硬编码的电子邮件地址,而是询问 Outlook 已经设置了哪些地址。

我正在考虑使用过滤器(例如 .... 以“@myonbehalfdomain.com”结尾)

所以在下面的示例中:Eonbehalf 应该获得第二个电子邮件地址,我可以在新电子邮件中使用下拉“发件人”字段看到该地址。

有道理吗?

Sub CreateNewMail()

    Dim olNS As Outlook.NameSpace

    Dim oMail As Outlook.MailItem

    Set olNS = Application.GetNamespace("MAPI")

    Set oMail = Application.CreateItem(olMailItem)

    strbody = "<BR><BR><BR>"

    SigString = Environ("appdata") & _

                "\Microsoft\Handtekeningen\custom.htm"


    If Dir(SigString) <> "" Then

        Signature = GetBoiler(SigString)

    Else

        Signature = ""

    End If


    On Error Resume Next

    Eonbehalf = getemailaddress(2)

        oMail.SentOnBehalfOfName = Eonbehalf

        oMail.Display

        oMail.HTMLBody = strbody & Signature

    Set oMail = Nothing

    Set olNS = Nothing


End Sub

【问题讨论】:

  • 用户应该选择地址吗?
  • @Damian,不,我想使用以“@certaindomain.com”结尾的电子邮件地址......所以我有我的主要帐户(test@test.com)和一个代表(test @certaindomain.com)。我想要第二个(test@certaindomain.com)或者如果那不可能:我想要一个来自我的主电子邮件地址(测试)的字符串,这样我就可以自己编译 sentonbehalfname。

标签: vba outlook


【解决方案1】:

根据我的经验,电子邮件可以通过两种方式在 Outlook 中用作“代表发送”:

  • 作为附加/单独帐户
  • 作为对共享文件夹/邮箱的访问,在这种情况下,它在帐户集合中不可见

对于第一种情况,尝试循环访问 Accounts 集合:

Sub getAccount()

Set oNS = Application.GetNamespace("MAPI")

    For Each oAccount In oNS.Accounts
    'your code goes here (read oAccount.DisplayName for example)
    Next oAccount

End Sub

在后一种情况下:

Sub getFolder()

Set oNS = Application.GetNamespace("MAPI")

    For Each oFolder In oNS.Folders
        'your code goes here (read oFolder.Name for example)
    Next oFolder

End Sub

******************************编辑****************** ************

尝试用fnGetSecondAdress("theEmailDomainYouReLookingFor")替换getemailaddress(2)

并将以下函数添加到您的代码中

Function fnGetSecondAdress(strDomain As String)

Dim strAddress As String


Set oNS = Application.GetNamespace("MAPI")

    For Each oFolder In oNS.Folders
                If InStr(1, oFolder.Name, strDomain, vbTextCompare) >= 1 And InStr(1, oFolder.Name, "Public Folders", vbTextCompare) = 0 Then
                    strAddress = oFolder.Name
                End If
    Next oFolder


fnGetSecondAdress = strAddress

End Function

【讨论】:

  • 后一种情况是我的!但是,缺乏基本的 VBA 知识使我无法完成我的任务。 Sub CreateNewMail() Dim olNS As Outlook.NameSpace Dim oMail As Outlook.MailItem Set olNS = Application.GetNamespace("MAPI") Set oMail = Application.CreateItem(olMailItem) For Each oFolder In olNS.Folders If InStr(oFolder , "certaindomain.com") Then test = oFolder.Name End If Next oFolder 所以我想让你“测试”为 SentonBehalf ...我做错了什么?
  • 已编辑原始答案,请检查它是否适合您。如果您要查找的域出现在 Outlook 中的许多共享文件夹/帐户中,则可能需要进行额外的调整
猜你喜欢
  • 2013-01-28
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多