How to choose which Outlook Account a Mailitem is sent from - reliably using SendUsingAccount

前端 未结 1 1541
无人共我
无人共我 2021-01-22 10:34

Let\'s say you have several accounts attached to your Outlook client and want to be able to choose which one to send a mail from using VBA. What do you do? The MailItem.SendUs

相关标签:
1条回答
  • 2021-01-22 10:52

    With Exchange accounts only, I reproduced your results. The problem could be in your code.

    I can set SendUsingAccount on mailitem.

    Sub sendFromEachAccount()
    
        Dim olAccounts As Accounts
        Dim olMsg As mailItem
        Dim i As Long
    
        Dim accountCount As Long
        accountCount = Session.Accounts.count
    
        For i = 1 To accountCount
    
            Set olMsg = CreateItem(olMailItem)
    
            Debug.Print "Account: " & i & ": " & "DisplayName: " & Session.Accounts(i).DisplayName
    
            With olMsg
                .SendUsingAccount = Session.Accounts.Item(i)
                .Display
            End With
    
        Next i
    
    ExitRoutine:
        Set olMsg = Nothing
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题