I often send emails on behalf of another user. I'd like to use VBA to automatically CC that user every time I send an email from/on behalf of that user.
I'm not familiar with VBA for Outlook but I'm thinking you could write an if statement that says "if sending message from UserX, cc UserX". The code should run automatically any time an email is sent on behalf.
SentOnBehalfOfName is tricky. It is usually empty until the item has been sent.
With this code in ThisOutlookSession you should find it blank.
Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim myRecipient As Recipient
Debug.Print " item.SentOnBehalfOfName - " & item.SentOnBehalfOfName
If item.SentOnBehalfOfName = "someone@somewhere.com" Then
Set myRecipient = item.Recipients.Add("Someone Else")
myRecipient.Type = olCC
item.Recipients.ResolveAll
End If
End Sub
At least one way to get around this:
Sub createSentOnBehalf()
Dim objMsg As mailitem
Set objMsg = Application.CreateItem(olMailItem)
objMsg.SentOnBehalfOfName = "someone@somewhere.com"
objMsg.Display
Set objMsg = Nothing
End Sub
Sub replySentOnBehalf()
Dim objMsg As mailitem
Set objMsg = ActiveInspector.currentItem.reply
objMsg.SentOnBehalfOfName = "someone@somewhere.com"
objMsg.Display
Set objMsg = Nothing
End Sub
Edit: Just realized you could set the cc while creating / replying rather than waiting until ItemSend.
Edit2: Move the cc code from itemsend
Sub createSentOnBehalf()
Dim objMsg As mailitem
Dim myRecipient As Recipient
Set objMsg = Application.CreateItem(olMailItem)
objMsg.SentOnBehalfOfName = "someone@somewhere.com"
Set myRecipient = objMsg.Recipients.Add("Someone Else")
myRecipient.Type = olCC
objMsg.Recipients.ResolveAll
objMsg.Display
Set objMsg = Nothing
End Sub
This will do what you are looking for (It is the first Google results of "always CC myself Outlook")
http://www.extendoffice.com/documents/outlook/1108-outlook-auto-cc.html
- Launch your outlook 2013 or 2010, and make sure that you are in the mail section. Then click Home > Rules > Manage Rules & Alerts.
- After selecting Manage Rules & Alerts option, the Rules and Alerts dialog will popup. Under E-mail Rules, click New Rule option.
- In the Rules Wizard, click Apply rule on messages I send then click Next to continue.
Then another dialog pops up.
(1.) In Step 1, check through the specified account box. In Step 2, please click on the word - specified.
(2.) And then click the Account drop down list to choose the account that you want to apply this rule.
- After selecting the account, and click OK to return to the previous window, you will see the selected account showing in the Rules Wizard. Then click on Next button.
(1.) In this wizard, check Cc the message to people or public group box, and then click on people or public group in step 2.
(2.) In the Rule Address dialog box, double click your cc recipient to add the address to the To-> text box, (If I want to cc myself, I will select or type my own email address in the To-> column.), finally click OK.
- It returns to the previous window, and you can see the cc recipient address appearing. Then click Finish button.
- Now, it returns to the very beginning dialog, click OK button, then the cc rule will be created. If you don’t want to enable the rule, uncheck it.
Then after sending or forwarding an email message to others with your specified account, your account or your specific cc recipient will always receive the same message.
It looks like you need to handle the ItemSend event of the Application class. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program. Note, the Cancel parameter allows to cancel the process of sending the email.
In the ItemSend event handler you can check out the SentOnBehalfOfName property of the item passed as a parameter and add the CC recipient using the Recipients property of the MailItem class. The Recipients collection provides the Add method for adding recipients.
Set myRecipient = myItem.Recipients.Add("Dan Wilson")
myRecipient.Type = OlMailRecipientType.olCC
After don't forget to call the Resolve or ResolveAll method of the Recipient class to resolve a Recipient object against the Address Book.
See How To: Fill TO,CC and BCC fields in Outlook programmatically for more information.