Set .SentOnBehalfofName on every email sent

ExPerseides picture ExPerseides · Oct 25, 2015 · Viewed 12.7k times · Source

I am trying to set the .SentOnBehalfOfName on every email I send through Outlook 2016. That is, whenever I hit New Mail, Reply, Reply All, or Forward.

I tried this:

Public WithEvents myItem As Outlook.MailItem

Private Sub Application_ItemLoad(ByVal Item As Object)
    If (TypeOf Item Is MailItem) Then
        Set myItem = Item
    End If
End Sub


Private Sub FromField()

With myItem
    .SentOnBehalfOfName = "[email protected]"
    .Display
End With

End Sub


Private Sub myItem_Open(Cancel As Boolean)

    FromField

End Sub

Answer

Eugene Astafiev picture Eugene Astafiev · Oct 25, 2015

The SentOnBehalfOfName property makes sense only in case of Exchange profiles/accounts. Moreover, you need to have the required permissions to send on behalf of another person. See Issue with SentOnBehalfOfName for a similar discussion.

In case if you have multiple accounts configured in the profile you can use the SendUsingAccount property which allows to an Account object that represents the account under which the MailItem is to be sent.

 Sub SendUsingAccount() 
  Dim oAccount As Outlook.account 
  For Each oAccount In Application.Session.Accounts 
   If oAccount.AccountType = olPop3 Then 
    Dim oMail As Outlook.MailItem 
    Set oMail = Application.CreateItem(olMailItem) 
    oMail.Subject = "Sent using POP3 Account" 
    oMail.Recipients.Add ("[email protected]") 
    oMail.Recipients.ResolveAll 
    oMail.SendUsingAccount = oAccount 
    oMail.Send 
   End If 
  Next 
 End Sub