vbams-accessoutlook

Access cannot find secondary email account in order to use SendUsingAccount property; can send from secondary acct manually but not programmatically


Hello and thank you very much for any suggestions.

I have VBA code that sends Outlook emails via Access and works as expected, except that I cannot get it to send the emails from my secondary (non-default) Outlook account. To employ the SendUsingAccount property, I am using Minty's code from https://www.access-programmers.co.uk/forums/threads/sendusingaccount-is-not-working.299542/. However, Access cannot find my secondary account for some reason; when I run the test below, a value of only 1 is returned; it counts my personal/default account, but not my secondary one. I know that I have access to the secondary account, because I can manually send from that account via the "From" dropdown in the message window. I don't know what I'm missing here:

Function Count_Accounts()

    Dim OutApp As Object
    Set OutApp = CreateObject("Outlook.Application")
    Debug.Print OutApp.Session.Accounts.Count
    
End Function

If I could get the test above to return a value of 2, I believe I'd be able to successfully use Minty's code linked above. Currently, Minty's code can only find (and thus only send from) my personal account.

I would be very grateful for any assistance. Thank you.


Solution

  • .SentOnBehalfOfName works for me.

    I did not test the code from your link, but if everything else is working OK, this part of the code should be:

        With OutMail
            .To = Variable_To
            .CC = ""
            .BCC = ""
            .Subject = Variable_Subject
            .SentOnBehalfOfName = 'your@email.whatever'
            .Attachments.Add (VarAttachFile)
            .HTMLBody = Variable_Body & signature
            .Display                                 'or use .Send
            .ReadReceiptRequested = False
        End With