【问题标题】:VBA outlook change from of forwarded message转发消息的 VBA 前景更改
【发布时间】:2016-04-19 16:36:52
【问题描述】:

我正在尝试自动转发邮件,但在此过程中,将 From 字段更改为我们网络中的另一个电子邮件地址,该地址已添加到我的 Outlook(不是作为帐户,而是作为我自己帐户下的邮箱)我可以访问它)

Dim recip As String

Dim allRecips As String
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer
Dim oAccount As Outlook.Account

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders("CSR GER").Folders("Inbox").Folders("Folders").Folders("#Confirmations")

i = 1

For Each olMail In Fldr.Items

    If InStr(olMail.Subject, "XXX BKG CONFIRMATION: " & BL) <> 0 Then

Set Recipients = olMail.Recipients
 For i = Recipients.Count To 1 Step -1
 recip$ = Recipients.Item(i).Address
 Debug.Print recip$
If VBA.Left(recip$, 10) = "/o=NOL-APL" Then
 GoTo Line2
End If

 If i = 1 Then
     strDomain = strDomain & recip
 Else
     strDomain = strDomain & recip & "; "
 End If
Line2:

 Next i
sentby = strDomain

    Set myItem = olMail.Forward

    myItem.SentOnBehalfOfName = "CSR_EST@xxx.com"

 myItem.Recipients.Add sentby

myItem.Display

现在问题在于SentBehalfOfName。一旦myItem.Display 运行,From 字段实际上会正确显示 - CSR_EST@xxx.com 但在发送电子邮件后,您可以看到它是由找到正在转发的电子邮件的邮箱发送的 - “CSR GER”。

谁能帮我理解这里出了什么问题?

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    我自己想出来的,这里是供将来参考的:

    要使 .SentOnBehalfOfName 起作用,您需要先在转发的电子邮件中将其设置为 null,然后创建一个副本并在此处进行更改。

    Dim recip As String
    
    Dim allRecips As String
    Dim olApp As Outlook.Application
    Dim olNs As Namespace
    Dim Fldr As MAPIFolder
    Dim olMail As Variant
    Dim i As Integer
    Dim oAccount As Outlook.Account
    
    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.Folders("CSR    GER").Folders("Inbox").Folders("Folders").Folders("#Confirmations")
    
    i = 1
    
    For Each olMail In Fldr.Items
    
          If InStr(olMail.Subject, "XXX BKG CONFIRMATION: " & BL) <> 0 Then
    
     Set Recipients = olMail.Recipients
    For i = Recipients.Count To 1 Step -1
    recip$ = Recipients.Item(i).Address
    
      If VBA.Left(recip$, 10) = "/o=NOL-APL" Then
           GoTo Line2
      End If
    
      If i = 1 Then
            strDomain = strDomain & recip
      Else
            strDomain = strDomain & recip & "; "
      End If
    
       Line2:
    
    Next i
    sentby = strDomain
    
    Set myItem = olMail.Forward
    
     myItem.SentOnBehalfOfName = "" ' <- set value to null
    
    myItem.Recipients.Add sentby
    
    Set ittm = myItem.Copy ' <- copy the forwarded email  
    
     With ittm
    
     .SentOnBehalfOfName = "CSR_EST@xxx.com"
    
     .Display
    
     End With
    
     myItem.Delete '<- remove the forwarded email
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 2013-07-23
      相关资源
      最近更新 更多