【问题标题】:Outlook Recipient address in to field字段中的 Outlook 收件人地址
【发布时间】:2016-05-28 19:57:42
【问题描述】:

如果从帐户发送的 Outlook 已更改并且某些字段已自动填写,我正在创建自定义回复。

首先我将解释它是如何工作的,我们会收到一封电子邮件。接收此电子邮件的电子邮件地址在抄送中。我在顶部栏中创建了一个按钮。当我按下此按钮时,将打开一个新的电子邮件屏幕,其中一些信息已经填写,其余信息我们需要自己填写。

大多数情况下,我已经完成了所有设置。但有一件事我不能上班。我希望将新电子邮件发送到原始 TO(收件人)地址。

现在我有这个代码:

Sub ReplyUsingAccount()
Dim oAccount As Outlook.Account
Dim objItem As Outlook.MailItem
Dim oMail As Outlook.MailItem
Dim strAcc As String
Dim i As Long
Set objItem = ActiveExplorer.Selection.Item(1)
strAcc = "myemail@email.nl"
For Each oAccount In Application.Session.Accounts
    If oAccount.DisplayName = strAcc Then
        Set oMail = Application.CreateItem(olMailItem)
        With oMail
            .SendUsingAccount = oAccount
            .To = objItem.RecipientEmailAddress
            .Subject = "Aangaande uw bestelling bij "
                       .HTMLBody = "<br><br><br>" & _
                        "<hr width=""50%"" size=""2"" noshade />" & _
                        "<font color=""#6699ff"">" & _
                        objItem.HTMLBody & "</font>"
            .Display
        End With
    End If
Next oAccount
Set oAccount = Nothing
Set objItem = Nothing
Set oMail = Nothing
End Sub

.To = objItem.RecipientEmailAddress 不起作用。 任何人都有解决方案。

提前致谢。

【问题讨论】:

    标签: vba email outlook


    【解决方案1】:

    我认为RecipientEmailAddress 在 VBA 中无效。

    试试SenderEmailAddress.

    【讨论】:

      【解决方案2】:

      要将所有收件人地址移至 .To 字段,示例如下。

      Option Explicit
      Sub Example()
          Dim olItem As Outlook.MailItem
          Dim olReply As MailItem ' Reply
          Dim Recipient As Outlook.Recipient
          Dim olRecip As String
      
          If Application.ActiveExplorer.Selection.Count = 0 Then
              MsgBox "No Item was Selected "
              Exit Sub
          End If
      
          For Each olItem In Application.ActiveExplorer.Selection
              Set olReply = olItem.Reply
      
              For Each Recipient In olItem.Recipients
                  olRecip = Recipient.address & ";" & olRecip
              Next Recipient
      
              With olReply
                  .To = olRecip ' all the Recipient
                  .Subject = "Aangaande uw bestelling bij "
                             .HTMLBody = "<br><br><br>" & _
                              "<hr width=""50%"" size=""2"" noshade />" & _
                              "<font color=""#6699ff"">" & _
                              olReply.HTMLBody & "</font>"
                  .Display
              End With
      
          Next
      
      End Sub
      

      添加发件人地址.To = olRecip &amp; ";" &amp; olItem.SenderEmailAddress

      【讨论】:

        【解决方案3】:

        我想它不会返回 SMTP 电子邮件地址,因为您使用的是在内部电子邮件地址上返回 .SenderEmailAddress 属性(这意味着它将是 EX 类型的地址,而不是 @987654325 @)。

        下面将返回内部和外部的SMTP 地址。

        Dim oOutlook As Outlook.Application
        Dim senderAddress As String, recipEntryId As String, SmtpMailAddress As String
        Dim oAddressEntry As Outlook.AddressEntry, oExchangeUser As Outlook.ExchangeUser
        Dim oReply As Outlook.MailItem, oRecipient As Outlook.Recipient
        Dim objItem As Outlook.MailItem
        
        If objItem.SenderEmailType = "SMTP" Then
        
            senderAddress = objItem.SenderEmailAddress
        
        Else
        
            Set oReply = objItem.Reply()
            Set oRecipient = oReply.Recipients.Item(1)
        
            recipEntryId = oRecipient.EntryID
        
            oReply.Close OlInspectorClose.olDiscard
        
            recipEntryId = oRecipient.EntryID
        
            Set oAddressEntry = oOutlook.GetAddressEntryFromID(recipEntryId)
            Set oExchangeUser = oAddressEntry.GetExchangeUser()
        
            senderAddress = oExchangeUser.PrimarySmtpAddress()
        
        End If
        
        SmtpMailAddress = senderAddress
        

        然后您可以使用getSmtpMailAddress 变量作为.To 电子邮件地址。

        如果您使用的是 Outlook 2010 或更高版本,则可以使用 .PropertyAccessor Property。我从来没有使用过这个,但它可能值得研究。

        【讨论】:

          猜你喜欢
          • 2022-07-26
          • 2012-09-20
          • 2012-12-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-04
          • 1970-01-01
          • 2020-12-10
          相关资源
          最近更新 更多