none
SendUsingAccount Does Not Work in Outlook 2010, possible bug? RRS feed

  • Question

  • Hi,

    I have been scratching my head for 2 days over this but it seems to me that there is a bug with Outlook 2010 where SendUsingAccount does not work. To be more specific SendUsingAccount does update the entry for the MailItem however the "From" entry in the display window does not get updated. Can anybody please confirm this bug?

    Saturday, July 20, 2013 2:14 AM

All replies

  • Hi PC_Meister,

    Thank you for your question. But I failed to reproduce your issue on my lab machine. Could you please provide me some code to re-produce this issue?

     Here is my sample code:

    Sub SendUsingAccount()
     
     Dim oAccount As Outlook.Account
     Dim oMail As Outlook.MailItem
     
     Set oAccount = Application.Session.Accounts.Item(1)
     
     Set oMail = Application.CreateItem(olMailItem)
     
     oMail.Subject = "Sent using MAPI Account"
     
     oMail.Recipients.Add "xxx@microsoft.com"
     
     oMail.Recipients.ResolveAll
     
     oMail.SendUsingAccount = oAccount
     
     oMail.Send
    End Sub
    

    Regards,

    Jeffrey

    Monday, July 22, 2013 8:47 AM
    Moderator
  • Hi Jeff,

    Thank you for your response. The code I am using is shown below. Basically what I am trying to do is to have reply to a message in an inbox using a different account from the one associated with that inbox

    Sub ReplyFromMyAccount()
    Dim rpl As Outlook.MailItem
    Dim itm As Object
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
    Set rpl = itm.ReplyAll
    rpl.SendUsingAccount = Session.Accounts.Item(1)
    rpl.Display
    End If
    Set rpl = Nothing
    Set itm = Nothing
    End Sub


    Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
    Case "Inspector"
    Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    Set objApp = Nothing
    End Function


    Monday, July 22, 2013 11:08 PM
  • I know this is old, but to help others:

    Change 

    rpl.SendUsingAccount = Session.Accounts.Item(1)

    to

    Set rpl.SendUsingAccount = Session.Accounts.Item(1)

    Brad Scott Clermont Software Services, Inc. www.ClermontSoftware.com


    Thursday, December 26, 2013 12:07 PM
  • Hello PC_Meister,

    I have just tried to run your code in my Outlook 2013. It works like a charm, I even tried to use different accounts changing the index in the following way:

    rpl.SendUsingAccount = Session.Accounts.Item(2)
    

    Did you try to use pass another values? How many accounts do you have configured in Outlook?

    Just a wild thought: did you install the latest updates and service packs for Office/Outlook?

    Thursday, December 26, 2013 4:00 PM
  • Thanks for your reply but I am afraid that didn't work. 
    Monday, January 13, 2014 10:15 PM
  • Hello Eugene,

    Thanks for you reply. Yes it does work with Outlook 2013. It is a bug with 2010. I unfortunately cannot update the Outlook 2010, because I am part of a large corporation... This is such a silly bug though

    Monday, January 13, 2014 10:18 PM
  • Hi PC_Meister,

    The SendUsingAccount property of the MailItem class was introduced with Outlook 2007. It should work as expected in Outlook 2010. The MSDN page provides the following sample code:

    Sub SendUsingAccount()  
     Dim oAccount As Outlook.Account  
     For Each oAccount In Application.Session.Accounts  
     If oAccount.AccountType = olPop3 Then  
        Dim oMail As Outlook.MailItem  
        Set oMail = Application.CreateItem(olMailItem)  
        oMail.Subject = "Sent using POP3 Account"  
        oMail.Recipients.Add ("someone@example.com")  
        oMail.Recipients.ResolveAll  
        oMail.SendUsingAccount = oAccount  
        oMail.Send  
     End If  
     Next  
    End Sub 
    

    Did you to send e-mails using the code listed above? Do you see the right/chosen sender name?

    Finally, if it is a "real" bug, you need to install updates and service packs that may fix the issue. Do you know the other way of fixing issues? :)

    Tuesday, January 14, 2014 2:00 PM
  • I do have the same problem as PC_Meister

    Also using Outlook 2010.

    This code I use:

    For Each loAccount In Session.Accounts
      If loAccount.SmtpAddress = myemail@example.com Then
        Set loAccountFrom = loAccount
      End If
    Next

    'loAccountFrom is a valid account object

    Set oMail = Application.CreateItem(olMailItem)
    oMail.Subject = "Sent using POP3 Account"
    oMail.Recipients.Add ("someone@example.com")
    oMail.Recipients.ResolveAll
    oMail.SendUsingAccount = loAccountFrom
    oMail.Send

    but unfortunately, only the from account is used of the default account file (not even the default e-mail address).

    When I select the account using the interface, the account is selected, via the code not!

    The default account is a Exchange account, the other account is an imap/smtp account.

    When I change the account first using the interface and run the code, the SendUsingAccount is changed correctly. So when there is NO object on SendUsingAccount, you can't add it or change it...

    Please help with a solution...



    Tuesday, January 14, 2014 9:50 PM
  • Hello Edwin,

    Do you have that latest updates and service packs installed for Outlook 2010? Could you please tell me the build number of your Outlook? Is it x64 or x86 based app?

    Wednesday, January 15, 2014 8:17 AM
  • For SendUsingAccount in VBA no "Set" is used. Starting in Outlook 2007 new objects in the object model use Set if an object is being set, not if an object property is being set. So no Set for SendUsingAccount. Previously Set was used for everything, objects and object properties. The decision was made in 2007 to rationalize all newly added objects and properties.

    The From address in the UI isn't changed until the item is either saved or sent, when SendUsingAccount is used. That's normal.

    Are you saying that after setting the property to a valid Account object that the alternate email account was not used for sending?


    Ken Slovak MVP - Outlook

    Wednesday, January 15, 2014 6:14 PM
    Moderator
  • Ken, you say no Set is used, but my experience in Access 2010 is different. In the snippet below, if I did not use the keyword Set, I got no error, but the code did not work. When I added the keyword Set, everything worked as intended. Perhaps there is a situation where Set is required and others where it should not be used?

    I should clarify that this is Access VBA - perhaps other languages are different.

        Set objOutlookApp = CreateObject("Outlook.Application")
        Set objOutlookEmail = objOutlookApp.CreateItem(olmailitem)
        
        'Find the index of the from address
        If (strFrom <> "") Then
            binFound = False
            For Each objAccount In objOutlookApp.Session.Accounts
                If (objAccount.SmtpAddress = strFrom) Then
                    binFound = True
                    Exit For
                End If
            Next
            
            If (Not binFound) Then
                logWriteErrorDual "Invalid From Address " & strFrom & ". It is not one of the Outlook Choices.", vbExclamation, "emlSendEmail"
                emlSendEmail = False
                Exit Function
            End If
                
            Set objOutlookEmail.SendUsingAccount = objAccount
        End If


    Brad Scott Clermont Software Services, Inc. www.ClermontSoftware.com


    Wednesday, January 15, 2014 8:49 PM
  • No Set is used in the VBA example in the Outlook Object Browser Help for SendUsingAccount(), and it works that way here. I haven't tried it in Access code however.

    This is the example from the Outlook Help:

    Sub SendUsingAccount()

    Dim oAccount As Outlook.account

    For Each oAccount In Application.Session.Accounts

    If oAccount.AccountType = olPop3 Then

    Dim oMail As Outlook.MailItem

    Set oMail = Application.CreateItem(olMailItem)

    oMail.Subject = "Sent using POP3 Account"

    oMail.Recipients.Add ("someone@example.com")

    oMail.Recipients.ResolveAll

    oMail.SendUsingAccount = oAccount

    oMail.Send

    End If

    Next

    End Sub


    Ken Slovak MVP - Outlook

    Wednesday, January 15, 2014 10:37 PM
    Moderator
  • Well, Ken, I had tried the example code, and it failed. When I added the keyword Set, it worked. Perhaps it is different in other applications, but this way people who cannot get it to work one way may be able to get it to work the other. It is quite easy to try both and see what works.

    Brad Scott Clermont Software Services, Inc. www.ClermontSoftware.com

    Thursday, January 16, 2014 12:28 AM
  • I tried this code in Access 2010 in a code module and it worked just fine with no Set for SendUsingAccount.

    I set it so the send using account was the second one in my Outlook profile, not the default email address. I added Dim's and set a reference to the Outlook object model in the Access project. Here's the code I tested:

    Sub testAccessOLCode()
        Dim objOutlookApp As Outlook.Application
        Dim objOutlookEmail As Outlook.MailItem
       Set objOutlookApp = CreateObject("Outlook.Application")
        Set objOutlookEmail = objOutlookApp.CreateItem(olmailitem)
        objOutlookEmail.SendUsingAccount = objOutlookApp.Session.Accounts.Item(2)
        objOutlookEmail.Save
        objOutlookEmail.Display
    End Sub

    When the item was displayed the From address was the one for my #2 email account in the profile.


    Ken Slovak MVP - Outlook

    Thursday, January 16, 2014 4:24 PM
    Moderator
  • Hello,

    I have the same issue in Microsoft Office Professional Plus 2010.

    Outlook sends mails from default account. 

    import win32com.client
    theApp = win32com.client.Dispatch("Outlook.Application")
    Msg = theApp.CreateItem(0)
    Msg.SendUsingAccount = theApp.Session.Accounts[u'...']
    Msg.To = "..."
    Msg.Subject = "..."
    Msg.Body = "..."
    Msg.Send()

    When I print theApp.Session.Accounts[u'...'].DisplayName it shows a valid account name, but If I do "print Msg.SendUsingAccount" it prints "None", so it looks like SendUsingAccount is read-only property.

    Tuesday, April 1, 2014 4:52 PM
  • You can't print an Account, try one of the properties of the SendUsingAccount object, such as UserName, DisplayName or SmtpAddress.

    Ken Slovak MVP - Outlook

    Tuesday, April 1, 2014 5:19 PM
    Moderator
  • I have to say that the feature works in VBA on the same environment (where python script has been executed).

    Wednesday, April 2, 2014 1:17 PM
  • If it works in VBA code it should work in other code, if the other code is written correctly and if other things such as code execution permissions are set correctly.

    Does working with properties of SendUsingAccount work any better if you try to use them after saving the item, or during a Send() event for the item or at the Application.ItemSend() level?


    Ken Slovak MVP - Outlook

    Wednesday, April 2, 2014 1:38 PM
    Moderator
  • Ken, thanks for your interest. Saving mail before sending gives the same result (default account is used).  I will try to find other solution of my problem. Most probably I will use VBA.
    Wednesday, April 2, 2014 2:30 PM
  • When you're running your code, are you running it in an application that's running under the correct Windows user identity? Your code should run under the Windows identity that has the Outlook profile and user accounts you need.

    It also should not run in a Windows service, other service, scheduled task or from a Web server. It should be run under normal user permissions.

    Are all those things correctly set up?


    Ken Slovak MVP - Outlook

    Wednesday, April 2, 2014 2:58 PM
    Moderator
  • Probably I've found the error in my version of win32com python library (maybe error presents in the latest win32com, I will check and report a bug if needed).

    The problem is that the property is updated with DISPATCH_PROPERTYPUT wFlags value, but should be updated with DISPATCH_PROPERTYPUTREF

    theApp = win32com.client.Dispatch("Outlook.Application")
    Msg = theApp.CreateItem(win32com.client.constants.olMailItem)
    account = outlook.Session.Accounts[u'...']
    Msg._oleobj_.Invoke(*(64209, 0, 8, 0, account))     # Msg.SendUsingAccount = account
    Msg.To = "..."
    Msg.Subject = "..."
    Msg.Body = "..."
    Msg.Send()



    Friday, April 4, 2014 1:59 PM
  • I know this is a very old post but despite this thought I would contribute as I had the same issue whilst working in a legacy Access App and may be my experience will help another late starter.

    Our environment is Access 2013 VBA app ported from Access 2010 with some clients still running Outlook 2010 and others Outlook 2013. To help with the "reference" issues I have started porting the code to use Late Binding on the objects. The original code early binding code used the same approach as discussed with "NO SET" required. I will however point out that we are using a small function to find the mail account we are after based on the smtpaddress as our users can have multiple mailboxes in outlook. This search needs to be case sensitive. That aside I had this all working for several months until I put the late binding code in place and then it started to use the default account - DESPITE being explicitly told to use a certain account.

    As a test I used the SET command and this proved to be successful. The exert of the relevant code is ...

    ' MAINLINE CODE

       iAcctID = getAccountID(oOutlook, sSendFrom)

        If (iAcctID > 0) Then
            Set oMailItem.SendUsingAccount = oOutlook.Session.Accounts.Item(iAcctID)
        End If


    Function getAccountID(oOutlook As Object, sAcctName As String) As Integer

        Dim i As Integer

        getAccountID = 0
        For i = 1 To oOutlook.Session.Accounts.count
            If StrComp(LCase(oOutlook.Session.Accounts.Item(i)), LCase(sAcctName), vbBinaryCompare) = 0 Then
                getAccountID = i
                Exit For
            End If
        Next i

    End Function

    Monday, March 21, 2016 12:47 AM
  • I know this is old but this just helped me.  In case it will help someone else I add this.

    I am creating a mail in VBA in Access 2010  going to outlook 2010.  

    I use early binding when I develop as it helps development, but late binding for the final build.  

    I noticed:

     oMailItem.SendUsingAccount= ....     works fine with early binding but does nothing with late binding no errors are generated either.

     Set oMailItem.SendUsingAccount= ....      works fine with late binding but generates an error with early binding.

    In practice I use compiler directive to switch as needed between development and production.


    • Edited by axleG01 Tuesday, October 11, 2016 4:58 PM
    • Proposed as answer by Reproba Friday, January 27, 2017 3:17 PM
    Tuesday, October 11, 2016 4:58 PM
  • It did help me today, i couldn't find anywhere on the net how to properly setup the account to be used because most of us are using a with:

    With oMailItem
         .SendUsingAccount = OutApp.Session.Accounts.Item(2)
    ...

    When the right method is:

    With oMailItem
         Set .SendUsingAccount = OutApp.Session.Accounts.Item(2)
    ...

    Thank you Brad!!

    Tuesday, December 6, 2016 8:12 PM
  • Sirs

    You are lifesavers. This has been driving me nuts. Every example i could find didn't work until I put three little letters in front of the command and was rewarded with the glorious sight of an email from the non-default account.

    For some reason I am having trouble with early binding using Outlook within Excel VBA (same versions, 2013, Outlook olb registered but i get errors trying to use the Outlook object model - another thing to look at) and so changed to late binding but couldn't get this damn thing to work.

    My week is ending on a high thanks to you and i might even take my wife out to dinner.

    Friday, January 27, 2017 3:16 PM
  • Glad you got it working. It is confusing.

    Brad Scott Clermont Software Services, Inc. www.ClermontSoftware.com

    Friday, January 27, 2017 4:21 PM
  • Thank you Brad Scott! Fixed my problem :-)

    • Edited by DidiWatson Tuesday, March 28, 2017 7:41 PM
    Tuesday, March 28, 2017 7:41 PM
  • How would I be able to mimic "Set" in PowerShell? I used to be able to update the .SendUsingAccount property with an account, but then I updated PowerShell from 4.0 to 5.1 and it no longer works.

    Like someone else mentioned, if I set the 'From' account in the GUI (after creating the mail item in PowerShell), then the .SendUsingAccount property has an object stored in that I can then set to a different account (using the = operator). But otherwise, the .SendUsingAccount property is empty, and using the (=) operator does not work anymore in PoSh 5.1 for me.

    Any ideas? Thanks!

    Friday, April 21, 2017 3:13 PM
  • How would I be able to mimic "Set" in PowerShell? I used to be able to update the .SendUsingAccount property with an account, but then I updated PowerShell from 4.0 to 5.1 and it no longer works.

    Like someone else mentioned, if I set the 'From' account in the GUI (after creating the mail item in PowerShell), then the .SendUsingAccount property has an object stored in that I can then set to a different account (using the = operator). But otherwise, the .SendUsingAccount property is empty, and using the (=) operator does not work anymore in PoSh 5.1 for me.

    Any ideas? Thanks!

    Posting back to let you know I found a solution for in PowerShell 5. You need to invoke 'SetProperty' using this wrapper function:

    function Invoke-SetProperty {
      param(
        [__ComObject] $Object,
        [String] $Property,
        $Value 
      )
      [Void] $Object.GetType().InvokeMember($Property,"SetProperty",$NULL,$Object,$Value)
    }
    
    Invoke-SetProperty $oMail -Property "SendUsingAccount" -Value $oAccount
    Hope this helps! GLHF!

    Friday, April 21, 2017 10:15 PM
  • Sorry for the hijack!

    I am having a similar problem to the OP, in both Outlook 2010 and 2016. I am using only Exchange accounts - I want the default account to be used for everything, from any account. I add the additional account(s) as accounts, not additional mailboxes for an existing account.

    I am using this code which intercepts any new Inspector item where is hasn't been sent. This covers new emails, Reply, Reply All, Forward and Forward as Attachment.

    ThisOutlookSession:

    Option Explicit
    
    Public WithEvents Inspectors As Outlook.Inspectors
    Public WithEvents Inspector As Outlook.Inspector
    
    Private Sub Application_Startup()
    
        Set Inspectors = Application.Inspectors
        
    End Sub
    
    Private Sub Inspectors_NewInspector(ByVal NewInspector As Outlook.Inspector)
    
        Set Inspector = NewInspector
        
    End Sub
    
    Private Sub Inspector_Activate()
    
        If Inspector.CurrentItem.Class = olMail And Not Inspector.CurrentItem.Sent Then
        
            'Debug.Print "Before: " & Inspector.CurrentItem.SendUsingAccount
            Call ChangeSender(Inspector.CurrentItem)
            'Debug.Print "After: " & Inspector.CurrentItem.SendUsingAccount
            
        End If
        
    End Sub
    
    Private Sub Item_Close(Cancel As Boolean)
    
        Set Inspector = Nothing
        
    End Sub

    Module2:

    Sub ChangeSender(ByRef item As Outlook.MailItem)
    
        item.SendUsingAccount = DefaultMailAccount()
        
    End Sub

    Module1:

    Function DefaultMailAccount() As Outlook.Account
    
        Set DefaultMailAccount = Application.Session.Accounts(1)
        Exit Function
        
    End Function
    
    

    With all this code, I get this:

    New emails started from any account successfully have the default account set in the From box
    Reply, Reply All, Forward, Forward as Atttachment do no change, so the account used stays in the From box

    My accounts show in Outlook as 'mailbox@domain.com'. When I click new in any mailbox, the from field shows 'mailbox@domain.com'. When I click reply, reply all etc. the default account shows as 'mailbox@domain.com' but the additional account(s) show as just 'mailbox'. If I debug.print before and after using SendUsingAccount, this value is CORRECTLY being changed, only the Outlook inspector window is not being updated. The fact a reply shows as just 'mailbox' I think is causing this issue, because if I manually change the From box to the full 'mailbox@domain.com' for the additional account, NOT the default, then manually run the code above, I can see the from box dynamically change to the default account.

    Even though the value seems to be being changed in code but not in the inspector window, when hitting send I get told I do not have permission to send on behalf of the mailbox.

    This must be a bug, surely! EDIT: If I switch it around so I want to prefer the additional account for new, replies etc. from ANY mailbox, it works fine.

    We basically have team mailboxes but do NOT want messages sent from those mailboxes. This means when replying everyone has to ALWAYS manually change the From box to themselves.




    Monday, January 28, 2019 1:44 PM
  • I know this is old, but to help others:

    Change 

    rpl.SendUsingAccount = Session.Accounts.Item(1)

    to

    Set rpl.SendUsingAccount = Session.Accounts.Item(1)

    Brad Scott Clermont Software Services, Inc. www.ClermontSoftware.com


    Confirmed this fixed the issue.

    
    • Edited by WannaKatana Wednesday, April 17, 2019 1:49 PM
    Wednesday, April 17, 2019 1:48 PM