I receive invoices from suppliers that I want to quickly forward to a QBO (Quickbooks Online) email address that handles 'receipts/invoices' wherein it reads the attachments and parses the info within - this speeds up data entry.
The problem is that QBO only accepts these emails from specific email addresses (i.e., ones that are registered as accounts in QBO). So assume that QBO only accepts emails from "[email protected]". However I receive the invoices on "[email protected]" which is a shared Office 365 mailbox that "[email protected]" has access to.
So my macro (VBA) should forward the currently selected emails (found within the [email protected] mailbox) using the [email protected] sending address to [email protected].
The problem is that the forwarded email arrives in the recipient's mailbox as having come from [email protected]. When I .Display
(instead of .Send
), I see that the sending account is set "correctly" yet it still arrives from the wrong account. So I figured that something superficial is happening - I decided that after the window pops up (using .Display
), I would change the sending account to something else, then back to the intended sending account - and lo and behold, it works. So there's some setting/headers other than .SentOnBehalfOfName that I need to set to get this working as I don't want any user intervention.
Option Explicit
Public Sub SendToQBO()
Dim Email As Object
Dim Sender As String
Sender = "[email protected]"
For Each Email In ActiveExplorer.Selection
With Email.Forward
' Just send to myself for now until this is figured out
.To = Sender
'.To = "[email protected]"
.Subject = "Sent From Outlook"
.Body = Email.Body
.SendUsingAccount = Session.Accounts(Sender)
.SentOnBehalfOfName = Sender
.Send
' Using .Display instead shows the right sending address, but it's ineffective
' unless I select another, then select it again before manually sending.
' .Display
End With
Next
End Sub