Automatically cc the "send on behalf of" account

Matt Metz

Senior Member
Outlook version
Outlook 365 64 bit
Email Account
IMAP
Operating system::    Window 11
Outlook version:     Outlook 365
Email type or host:    IMAP

I often use the "send on behalf of" feature in Outlook 365. But I wish the email to always cc the account on which I'm sending on behalf.

Here is what I do today:
> click to send a new email from my account: e.g. me@mydomain.com
> Click on the FROM button and in the drop-down, click on OTHER EMAIL ADDRESS
> I type in the other email address: e.g., sales@mydomain.com (where mydomain is in fact, my own domain), then click OK
After sending it, the recipient sees the email as having come from me@mydomain.com ON BEHALF OF sales@mydomain.com.
But in my sent items folder, there is nothing to indicate the sent item used the ON BEHALF OF functionality - it simply shows as having come from me@mydomain.com.
To make it clear, when I do this process, I would like the on-behalf-of address to automatically be cc'ed on the message.

What VBA code will accomplish this for me - that is: WHEN AN EMAIL IS SENT ON BEHALF OF AN ACCOUNT, THAT ACCOUNT SHOULD AUTOMATICALLY BE CC'ED ON THE EMAIL. ?

Thank you for any assistance.
 
Works if I kluge the Mail.SentOnBehalfOfName. But I can't test in a live Exchange Environment.
STOP is there so you can walk it in the Debugger using F8.
Must be in ThisOutlookSession because of the Send Event hook.

General info on VBA, Self Cert, etc.
How to use Outlook's VBA Editor | Slipstick Systems

Code:
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)

    Stop

    '   If Not a MailItem - done
    '
    If Not TypeOf Item Is Outlook.MailItem Then Exit Sub
    Dim Mail As Outlook.MailItem
    Set Mail = Item
    
    '   If No Send on Behalf Of - done
    '
    If Mail.SentOnBehalfOfName = "" Then Exit Sub
    
    '   Add the OnBehalfOf Name as a Recipient
    '
    Dim OBORecipient As Outlook.Recipient
    Set OBORecipient = Mail.Recipients.Add(Mail.SentOnBehalfOfName)
    
    '   Change the OBORecipient to a BCC
    '
    OBORecipient.Type = Outlook.olBCC

End Sub
 
Works if I kluge the Mail.SentOnBehalfOfName. But I can't test in a live Exchange Environment.
STOP is there so you can walk it in the Debugger using F8.
Must be in ThisOutlookSession because of the Send Event hook.

General info on VBA, Self Cert, etc.
How to use Outlook's VBA Editor | Slipstick Systems

Code:
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)

    Stop

    '   If Not a MailItem - done
    '
    If Not TypeOf Item Is Outlook.MailItem Then Exit Sub
    Dim Mail As Outlook.MailItem
    Set Mail = Item
   
    '   If No Send on Behalf Of - done
    '
    If Mail.SentOnBehalfOfName = "" Then Exit Sub
   
    '   Add the OnBehalfOf Name as a Recipient
    '
    Dim OBORecipient As Outlook.Recipient
    Set OBORecipient = Mail.Recipients.Add(Mail.SentOnBehalfOfName)
   
    '   Change the OBORecipient to a BCC
    '
    OBORecipient.Type = Outlook.olBCC

End Sub
Thank you. I will try this. Note: this account I’m working with is an IMAP account and not Exchange. Does that matter?
 
This did not work. I've attached a screenshot of the error. I don't know enough about coding to figure out what needs to change in the code to address this error.

Screenshot 2026-01-07 050017.png
 
Did some more testing. No longer sure that my original approach will work. I'll play around with it and advise when I come up with a new method.
 
Just to be sure before I dive back in.

You are NOT using MS 365/Exchange shared mailboxes. Where you have been granted permissions to send on behalf of for a shared mailbox.

You ARE using a bog standard email account and when you want to send from another address you just click the [From] button and pick it from the list or enter it manually.

If so, the best I can come up with is:

For any email you send, where the From Address is not the default address for your profile, the code would add your default address as a CC.

(To see you default address: File -> Account Settings -> Account Settings. On the "Email tab" it's the one with the check mark)

Would this work for you?
 
Hornblower409, my apologies. I missed this last post from you (Jan 7). I appreciate your efforts to help. Here are my responses:
  • Correct: I am NOT using MS365/Exchange shared mailboxes. This is a simple IMAP account accessing my "wildcard" account on the Ionos server.
  • I am not familiar with your term "bog" but I am using a standard IMAP account. When I want to use this feature, yes, I click on "FROM" and then click on "OTHER EMAIL ADDRESS" and then type in the desired address (e.g. "test@mydomain.com") and ensure the SEND USING field is my Ionos wildcard account (*@mydomain.com).
  • But no, I don't want the DEFAULT address as the CC (which is *@mydomain.com); specifically, I want (in this case) test@mydomain.com to be CC'ed on the outgoing email.
 
How about this?

If FromAddress <> AccountDefaultAddress then
Add FromAddress to CC
End If
 
Thank you, Hornblower409. You suggested this code, but I don't know where it goes in the script above.

How about this?

If FromAddress <> AccountDefaultAddress then
Add FromAddress to CC
End If​

Can you reply with the entire VBA private sub code, please?

Thank you!

-Matt
 
I apologize for not understanding. Yes, that is the logic I would like to apply. I always use the same account to send this kind of message, and that account is *@mydomain.com.

When I use this process, the outgoing email shows:
Specifically, in the address above,
  • *@mydomain.com is the actual email account, and is, I assume, what you are calling "AccountDefaultAddress" and
  • mydvac@mydomain.com is what I assume you are calling "FromAddress"
I hope this answers your question.

Once again, I am most appreciative of your assistance!

-Matt
 
New Version.
Code:
' =====================================================================
' 2026-01-18_130913351
'
' RE: https://forums.slipstick.com/threads/102150-automatically-cc-the-send-on-behalf-of-account/
' Must be in ThisOutlookSession because of the ItemSend event hook.
'
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean)

    '   If Not a MailItem - done
    '
    If Not TypeOf Item Is Outlook.mailItem Then Exit Sub

    '   Cast the Item object to a MailItem
    '
    Dim Mail As Outlook.mailItem
    Set Mail = Item
    
    '   If not sending from an SMTP account - done
    '
    If Not Mail.SenderEmailType = "SMTP" Then Exit Sub
    
    '   If no On Behalf Of Name - done
    '
    If Mail.SentOnBehalfOfName = "" Then Exit Sub
    
    '   Add the Sender as a CC
    '
    Dim CCRecipient As Outlook.Recipient
    Set CCRecipient = Mail.Recipients.Add(Mail.SenderEmailAddress)
    CCRecipient.Type = Outlook.OlMailRecipientType.olCC
    
    '   Make sure the Sender address resolves
    '
    CCRecipient.Resolve
    If Not CCRecipient.Resolved Then
        MsgBox "CCRecipient did not Resolve." & vbCrLf & vbCrLf & CCRecipient.Address
        Mail.Recipients.Remove CCRecipient.Index
        Exit Sub
    End If
    
    '   Let it fly
    '
    
End Sub
 
Hornblower409,

Again, I am delighted that you are taking on this challenge. We are very close. This ran, without an error, but....


In other words, your comment
  • ' Add the Sender as a CC (and the subsequent commands)
Should be:
  • ' Add the SentOnBehalfOfName as a CC (and the subsequent commands)

We (YOU!) are very close.

Thank you for all your efforts!
 
Using your hard work, I was able to modify your code. I took your line
  • Set CCRecipient = Mail.Recipients.Add(Mail.SenderEmailAddress)
And replaced it with
  • Set CCRecipient = Mail.Recipients.Add(Mail.SentOnBehalfOfName)
Bada-bing, bada-boom.

Hornblower409, my hat is off to you.

Please tell me what your favorite charity is; I want to make a donation to it as a way to pay it forward to express my appreciation for what you have done for me.

-Matt
 
Also, FYI, I realized I could use BCC so I simply changed all "CC" in the code to "BCC." Thank you again!
 
I missed something. Forgot "Cancel = True" in case of a Resolve error. Needed to stop the Send if there is an error.

Code:
    If Not CCRecipient.Resolved Then
        MsgBox ...
        Mail.Recipients.Remove ...
        Cancel = True
        Exit Sub
    End If
 
Got it.

I am still requesting the name of your favorite charity so I can donate their to acknowledge your help!
 
Similar threads
Thread starter Title Forum Replies Date
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
D Is it possible to automatically send an email when it is moved to a folder? Exchange Server Administration 1
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2
R Email Send & Receive Turned off but sends automatically anyway Using Outlook 1
J Email won't send Automatically in Outlook 2010 Using Outlook 3
R Outlook 2010 Not Recieiving Emails Automatically, Have tohit Send / Recieve Using Outlook 1
S Outllok 2007 VBA code to send mail automatically from drafts folder Using Outlook 1
M Outlook 365 macro - automatically attach file based on subject line Outlook VBA and Custom Forms 0
kburrows Outlook Automatically Merging Contacts Using Outlook 2
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
A Opening a link from a specific sender automatically Outlook VBA and Custom Forms 4
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
Z Automatically adjust Outlook Reading Pane from bottom to right depending on portrait or landscape window Using Outlook 1
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
G automatically choosing "add to autocorrect" option Using Outlook 0
L Why are some email automatically going to "archive" Using Outlook 2
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 1
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
E Remove flag automatically Using Outlook 4
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
M Outlook 365 Switching from AOL to Yahoo automatically Using Outlook 5
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
Paul Hobbs Automatically accept "Empty Folders" prompt Outlook VBA and Custom Forms 6
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
W Automatically open attachments without automatically printing them Using Outlook 0
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1

Similar threads

Back
Top