2016-04-18 1 views
1

J'essaie de transférer automatiquement un message mais dans le processus, changez le champ From à une autre adresse e-mail dans notre réseau que j'ai ajouté à mon Outlook (pas comme un compte mais comme un Boîte aux lettres sous mon propre compte et je peux y accéder)VBA outlook change from du message transféré

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 = "[email protected]" 

myItem.Recipients.Add sentby 

myItem.Display 

maintenant, le problème est avec SentBehalfOfName. Une fois que myItem.Display s'exécute, le champ From s'affiche correctement - [email protected] mais après avoir envoyé l'e-mail, vous pouvez voir qu'il a été envoyé par la boîte aux lettres que l'e-mail transféré est trouvé - "CSR GER".

Quelqu'un peut-il m'aider à comprendre ce qui ne va pas ici?

Répondre

0

figured it out moi-même, voici ce qui fonctionne pour référence future:

Pour le .SentOnBehalfOfName fonctionne, vous devez d'abord le mettre à zéro dans l'e-mail envoyé, puis créer une copie et le modifier Là.

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 = "[email protected]" 

.Display 

End With 

myItem.Delete '<- remove the forwarded email