使用 Outlook VBA 获取 item.recipient

Get item.recipient with Outlook VBA

我需要从 Outlook 2010 上的项目中获取收件人电子邮件地址。

我的代码如下:

sSQL = "SELECT id from dbo.database where email_address LIKE '" & Item.RecipientEmailAddress & "'

item.recipientEmailAddress 无效,但我需要类似的东西。

我知道您有一个代码调用 Item.SenderEmailAddress 但在这种情况下,我需要收件人的电子邮件地址。

我已经看到了关于该主题的其他一些线程,但我没有设法使它们中的任何一个起作用。

对于 "quick" 的实现方式,您可以将 Item.ToItem.CCItem.BCC 属性连接在一起,但是,这可能不是您想要的正在寻找,因为有时这些属性存储显示名称而不是 SMTP 电子邮件地址。

另一种方法是使用 Item.Recipients 集合,其中包含一个 Recipient 对象,其中包含一个 Address 属性,用于每个收件人(TO、CC 和密件抄送).

您可以遍历每个收件人并将它们连接在一起。像这样:

Dim recip As Recipient
Dim allRecips As String

For Each recip In item.Recipients
    If (Len(allRecips) > 0) Then allRecips = allRecips & "; "
    allRecips = allRecips & recip.Address
Next

MailItem 的 Recipients 属性 class returns 表示 Outlook 项目的所有收件人的收件人集合。

Type property of the Recipient class returns or sets an integer representing the type of recipient. For the MailItem the value can be one of the following OlMailRecipientType 常量:olBCC、olCC、olOriginator 或 olTo。

收件人 class 还提供以下属性: