Steve Tomalin
Member
- Outlook version
- Outlook 2016 32 bit
- Email Account
- Outlook.com (as MS Exchange)
I have just completed a VBA macro, which intercepts all new emails I create or replies I generate from received emails (regardless of whether Reply, Reply-All or Forward has been clicked). The macro conditionally changes the default From Account to a different value and also adds a BCC address to select emails I send. Having used example code provided by Sue Mosher (plus others) and having received further assistance from Diane Poremsky here, in order to get this working properly, I volunteered to post my finished macro on this forum, including an explanation for what it does and why I needed it, hence this post. Hopefully, this example might come in handy, in one way or another, to someone else who may be attempting to achieve the same or similar objectives.
If you do require further explanation about what the macro does, or the background as to why I needed it, that information is included after the example code. I would not classify myself as a developer, so if you try to use the macro yourself and encounter any problems getting it working, I'm afraid it's probably unlikely that I will be able to assist you.
Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector
Private Sub Application_Startup()
Set m_Inspectors = Application.Inspectors
End Sub
Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
Set m_Inspector = Inspector
End Sub
Private Sub m_Inspector_Activate()
If TypeName(m_Inspector.CurrentItem) = "MailItem" And _
m_Inspector.CurrentItem.Sent = False Then
Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Set OutApp = Application
Set objMail = m_Inspector.CurrentItem
Dim strFrom1 As String
Dim strFrom2 As String
strFrom1 = "fred.bloggs@outlook.com"
strFrom2 = "fred.bloggs_other@outlook.com"
Dim strAccItem1 As String
Dim strAccItem2 As String
strAccItem1 = "5"
strAccItem2 = "6"
If objMail.Sent = False Then
If InStr(LCase(objMail.SendUsingAccount), strFrom1) Then
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(strAccItem1)
With objMail
Set objRecip = objMail.Recipients.Add(strFrom1)
objRecip.Type = olBCC
objRecip.Resolve
End With
ElseIf InStr(LCase(objMail.SendUsingAccount), strFrom2) Then
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(strAccItem2)
With objMail
Set objRecip = objMail.Recipients.Add(strFrom2)
objRecip.Type = olBCC
objRecip.Resolve
End With
End If
End If
End If
Set m_Inspector = Nothing
End Sub
What this Macro Does
Whenever I create a new email, or respond to an existing email using Reply, Reply-All or Forward, the macro runs. The macro tests the current value of the 'From' account in the open email and, if the 'From' value matches one of two particular values, it changes the From account value to one of two different values. In other words, (using the above example strings):
If the Display Value of the Send Account is currently 'fred.bloggs@outlook.com' in the open email, the macro changes the Send Account to the Account with the Item Value of 5. After that, fred.bloggs@outlook.com is added as a recipient to the BCC list.
Otherwise, if the Display Value of the Send Account is currently 'fred.bloggs_other@outlook.com' in the open email, the macro changes the Send Account to the Account with the Item Value of 6. After that, fred.bloggs_other@outlook.com is added as a recipient to the BCC list.
If the Display Value of the Send Account within the open email is anything else, the macro ends, changing nothing.
Why The Macro Was Needed
My requirement for this macro centred around the changes Microsoft made to Outlook.com, a year or so ago, when they swapped the original back end of Outlook.com for an Exchange based solution. In doing this, they ended providing full support for 'Custom Domains' within Outlook.com accounts and, instead, recommended that affected users should subscribe to an Office365 account. I resisted this approach and opted to deploy a different workaround instead.
There may very well be other approaches in solving what is/was the underlying problem here, but the approach I took seems to have been working quite well for me, with exception to an annoying manual step which, up until now, I had previously needed to perform on every email that I'd been sending from the custom domain email addresses associated with my Outlook.com accounts. That is why I needed the macro, to eliminate the manual intervention required when sending emails from Outlook on my PC. Not only was this repetitive, manual intervention inconvenient, but if inadvertently omitted, it merely emphasised the problem and could confuse the recipients of these errant emails into using the wrong email address(es) to communicate with me. The macro solves this issue.
Further Detail Regarding the Problem Which Necessitated the Workaround
I have used a couple of Outlook.com accounts as my email back end for the last few years. Each of these accounts had a 'Custom Domain' linked to the account as a Send Account and the Primary Alias of each account was my email address for the custom domain. All my email was sent as the Primary Aliases and (without close analysis of the email header information) none of the recipients of my emails would have been immediately made aware of any Outlook.com email accounts or addresses involved. When Microsoft upgraded their back end, the problem that arose for me affected all the emails that I sent from Outlook on my PC. The 'From' address details within the emails I was sending out to people suddenly started to include a statement along the lines of:
'From outlook_d32c5a9f8hf7ea66@outlook.com on behalf of Fred@Bloggs.me'
After various attempts and different approaches at fixing this, including creating new Outlook aliases for myself and changing my Primary Aliases within the accounts, this still only marginally improved the situation, resulting in a revised statement along the lines of:
"From Fred.Bloggs@Outlook.com on behalf of Fred@Bloggs.me"
I didn't want to advertise my Outlook.com email addresses, so this outcome was still completely unacceptable. In the case of my Outlook.com phone app and the Outlook.com webmail interface, there was/is still an option to select an alternative 'From' address within the emails that I send. The resultant emails do not include the 'sent on behalf of' statement within the From information, when received by the recipients, so I find this acceptable.
The Workaround
Using the dummy addresses quoted above as the example here, I still have the following email forwards set up within the host settings of my two custom domains:
Fred@Bloggs.me forwards to Fred.Bloggs@Outlook.com
Fred@BloggsOther.com forwards to Fred.Bloggs_Other@Outlook.com
Within Outlook on my PC, I still have the two Outlook.com accounts set up as IMAP accounts, where I receive all my incoming mail for my custom domain email addresses. However, I do not send mail out from these Outlook mailbox accounts. For that purpose I have two additional Send Only accounts configured within Outlook (Account Item Numbers 5 & 6), where I have specified the email address details and SMTP settings of the server I use to send out email for the Fred@Bloggs.me and Fred@BloggsOther.com addresses.
This arrangement solves the problem of ensuring that all emails sent out from Outlook on my PC are presented in exactly the way I want them to appear to the recipients. However, it introduced the problem of how to provide easy access to these sent emails within Outlook on my phone or within the Outlook.com webmail interface (which I occasionally need to do).
To solve this secondary issue, I simply ensure that all email sent from Outlook on my PC has my Outlook.com email address BCC'd on these items (I bought a utility to do this originally, but now the macro does this, as well as change the 'From' account). There is a rule configured within each of my Outlook.com accounts, so that any email arriving, where the sender is my own 'Custom Domain' email address, is moved into a Folder called 'PC Sent Items'.
That's about it! Some may consider it a bit 'clunky', but it works for me and avoided the need for me to pay for the monthly subscription to an Office365 account. The macro consequently automatically sets the correct From Account and adds the BCC address for every email I create or reply to that is sent from Outlook on my PC.
I hope some of this helps someone, at some point. Thanks again to Diane Poremsky, here on this forum, for all the help she gave me whilst I developed this macro.
Kind regards,
Steve Tomalin
If you do require further explanation about what the macro does, or the background as to why I needed it, that information is included after the example code. I would not classify myself as a developer, so if you try to use the macro yourself and encounter any problems getting it working, I'm afraid it's probably unlikely that I will be able to assist you.
Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector
Private Sub Application_Startup()
Set m_Inspectors = Application.Inspectors
End Sub
Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
Set m_Inspector = Inspector
End Sub
Private Sub m_Inspector_Activate()
If TypeName(m_Inspector.CurrentItem) = "MailItem" And _
m_Inspector.CurrentItem.Sent = False Then
Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Set OutApp = Application
Set objMail = m_Inspector.CurrentItem
Dim strFrom1 As String
Dim strFrom2 As String
strFrom1 = "fred.bloggs@outlook.com"
strFrom2 = "fred.bloggs_other@outlook.com"
Dim strAccItem1 As String
Dim strAccItem2 As String
strAccItem1 = "5"
strAccItem2 = "6"
If objMail.Sent = False Then
If InStr(LCase(objMail.SendUsingAccount), strFrom1) Then
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(strAccItem1)
With objMail
Set objRecip = objMail.Recipients.Add(strFrom1)
objRecip.Type = olBCC
objRecip.Resolve
End With
ElseIf InStr(LCase(objMail.SendUsingAccount), strFrom2) Then
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(strAccItem2)
With objMail
Set objRecip = objMail.Recipients.Add(strFrom2)
objRecip.Type = olBCC
objRecip.Resolve
End With
End If
End If
End If
Set m_Inspector = Nothing
End Sub
What this Macro Does
Whenever I create a new email, or respond to an existing email using Reply, Reply-All or Forward, the macro runs. The macro tests the current value of the 'From' account in the open email and, if the 'From' value matches one of two particular values, it changes the From account value to one of two different values. In other words, (using the above example strings):
If the Display Value of the Send Account is currently 'fred.bloggs@outlook.com' in the open email, the macro changes the Send Account to the Account with the Item Value of 5. After that, fred.bloggs@outlook.com is added as a recipient to the BCC list.
Otherwise, if the Display Value of the Send Account is currently 'fred.bloggs_other@outlook.com' in the open email, the macro changes the Send Account to the Account with the Item Value of 6. After that, fred.bloggs_other@outlook.com is added as a recipient to the BCC list.
If the Display Value of the Send Account within the open email is anything else, the macro ends, changing nothing.
Why The Macro Was Needed
My requirement for this macro centred around the changes Microsoft made to Outlook.com, a year or so ago, when they swapped the original back end of Outlook.com for an Exchange based solution. In doing this, they ended providing full support for 'Custom Domains' within Outlook.com accounts and, instead, recommended that affected users should subscribe to an Office365 account. I resisted this approach and opted to deploy a different workaround instead.
There may very well be other approaches in solving what is/was the underlying problem here, but the approach I took seems to have been working quite well for me, with exception to an annoying manual step which, up until now, I had previously needed to perform on every email that I'd been sending from the custom domain email addresses associated with my Outlook.com accounts. That is why I needed the macro, to eliminate the manual intervention required when sending emails from Outlook on my PC. Not only was this repetitive, manual intervention inconvenient, but if inadvertently omitted, it merely emphasised the problem and could confuse the recipients of these errant emails into using the wrong email address(es) to communicate with me. The macro solves this issue.
Further Detail Regarding the Problem Which Necessitated the Workaround
I have used a couple of Outlook.com accounts as my email back end for the last few years. Each of these accounts had a 'Custom Domain' linked to the account as a Send Account and the Primary Alias of each account was my email address for the custom domain. All my email was sent as the Primary Aliases and (without close analysis of the email header information) none of the recipients of my emails would have been immediately made aware of any Outlook.com email accounts or addresses involved. When Microsoft upgraded their back end, the problem that arose for me affected all the emails that I sent from Outlook on my PC. The 'From' address details within the emails I was sending out to people suddenly started to include a statement along the lines of:
'From outlook_d32c5a9f8hf7ea66@outlook.com on behalf of Fred@Bloggs.me'
After various attempts and different approaches at fixing this, including creating new Outlook aliases for myself and changing my Primary Aliases within the accounts, this still only marginally improved the situation, resulting in a revised statement along the lines of:
"From Fred.Bloggs@Outlook.com on behalf of Fred@Bloggs.me"
I didn't want to advertise my Outlook.com email addresses, so this outcome was still completely unacceptable. In the case of my Outlook.com phone app and the Outlook.com webmail interface, there was/is still an option to select an alternative 'From' address within the emails that I send. The resultant emails do not include the 'sent on behalf of' statement within the From information, when received by the recipients, so I find this acceptable.
The Workaround
Using the dummy addresses quoted above as the example here, I still have the following email forwards set up within the host settings of my two custom domains:
Fred@Bloggs.me forwards to Fred.Bloggs@Outlook.com
Fred@BloggsOther.com forwards to Fred.Bloggs_Other@Outlook.com
Within Outlook on my PC, I still have the two Outlook.com accounts set up as IMAP accounts, where I receive all my incoming mail for my custom domain email addresses. However, I do not send mail out from these Outlook mailbox accounts. For that purpose I have two additional Send Only accounts configured within Outlook (Account Item Numbers 5 & 6), where I have specified the email address details and SMTP settings of the server I use to send out email for the Fred@Bloggs.me and Fred@BloggsOther.com addresses.
This arrangement solves the problem of ensuring that all emails sent out from Outlook on my PC are presented in exactly the way I want them to appear to the recipients. However, it introduced the problem of how to provide easy access to these sent emails within Outlook on my phone or within the Outlook.com webmail interface (which I occasionally need to do).
To solve this secondary issue, I simply ensure that all email sent from Outlook on my PC has my Outlook.com email address BCC'd on these items (I bought a utility to do this originally, but now the macro does this, as well as change the 'From' account). There is a rule configured within each of my Outlook.com accounts, so that any email arriving, where the sender is my own 'Custom Domain' email address, is moved into a Folder called 'PC Sent Items'.
That's about it! Some may consider it a bit 'clunky', but it works for me and avoided the need for me to pay for the monthly subscription to an Office365 account. The macro consequently automatically sets the correct From Account and adds the BCC address for every email I create or reply to that is sent from Outlook on my PC.
I hope some of this helps someone, at some point. Thanks again to Diane Poremsky, here on this forum, for all the help she gave me whilst I developed this macro.
Kind regards,
Steve Tomalin