vba - 有没有办法列出当前 Outlook 会话中可访问的收件箱?
问题描述
我希望在 Outlook 会话中检索电子邮件收件箱列表(即所有可访问的收件箱、主要、共享和委派)。我所需要的只是这些收件箱的字符串电子邮件地址,因此下面的示例代码只是将它们打印在消息框中(当然,这不是它们实际发生的情况!)。
我想我只是很愚蠢,找不到要循环的相关属性?
以下似乎没有返回会话已授权访问的收件箱:
Public Sub PrintAccounts()
Dim accounts As Outlook.accounts
Set accounts = Application.Session.accounts
Dim account As Outlook.account
For Each account In accounts
MsgBox account.DisplayName
Next account
End Sub
非常感谢!
现在回答:
Private Sub DisplayedMailboxesNames()
Dim colStores As Stores
Dim oStore As Store
Set colStores = Session.Stores
For Each oStore In colStores
Debug.Print ResolveDisplayNameToSMTP(oStore.displayName)
Next
End Sub
Private Function ResolveDisplayNameToSMTP(displayName As String) As String
Dim oRecip As Outlook.Recipient
Dim oEU As Outlook.ExchangeUser
Dim oEDL As Outlook.ExchangeDistributionList
Set oRecip = Application.Session.CreateRecipient(displayName)
oRecip.Resolve
If oRecip.Resolved Then
Select Case oRecip.AddressEntry.AddressEntryUserType
Case OlAddressEntryUserType.olExchangeUserAddressEntry
Set oEU = oRecip.AddressEntry.GetExchangeUser
If Not (oEU Is Nothing) Then
ResolveDisplayNameToSMTP = oEU.PrimarySmtpAddress
End If
Case OlAddressEntryUserType.olExchangeDistributionListAddressEntry
Set oEDL = oRecip.AddressEntry.GetExchangeDistributionList
If Not (oEDL Is Nothing) Then
ResolveDisplayNameToSMTP = oEDL.PrimarySmtpAddress
End If
End Select
End If
End Function
解决方案
帐户与邮箱不同。
将所有可访问的邮箱添加到用户的 GUI,然后:
Private Sub DisplayedMailboxesNames()
Dim colStores As Stores
Dim oStore As Store
Dim oRoot As Folder
Set colStores = Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print oRoot.folderPath
Debug.Print oRoot.Name
Next
End Sub
推荐阅读
- spring - 在面向 Tasklet 的批处理中从数据库中读取数据
- mysql - MySQL日期时区输入
- c++ - CImage:复制 8 位 JPEG 会产生黑色图像
- javascript - javascript将数字与对象键进行比较并获取最小值
- python - 如何删除熊猫df中具有相同值但顺序不同的行?
- python - 如何从 Tensorflow 输入管道内的训练模型进行预测?
- scala - 在 Play 框架项目中将 firebase-messaging-sw.js 文件放在哪里?
- ajax - Ember:如果在控制器中设置了值,则执行 Ajax 命令(用模板编写),
- c - 返回星期几,并提供日、月、年和一月一日?
- emacs - 我如何为 Alembic 提供的依赖项命名?