SendUsingAccount not working - code not finding Mailbox Accounts

Posted on 2011-03-15
Last Modified: 2012-05-11
Hi, I've attempted to use the code from to send emails through outlook using a mail account other then my default account.  When I use my default account, the code works fine - email is sent.  But when I change it to refelct my other mail account, I get no errors, but the email is still sent using my default account.  In an attempt to figure out if the code was even seeing the other mail accounts I also have access to (3), I used the below code.  It returns 1 - which is only my default account

Sub Which_Account_Number()
    Dim OutApp As Outlook.Application
    Dim I As Long

    Set OutApp = CreateObject("Outlook.Application")

    For I = 1 To OutApp.Session.Accounts.Count
        MsgBox OutApp.Session.Accounts.Item(I) & " : This is account number " & I
    Next I

End Sub

I've tried a few different email codes, all work fine when I use my default email account.
I am at my wits end trying to figure out why the code does not recognize the Mail accounts.  I am able to manually send emails with no issues so I don't think it is an access issue.  Can you please help me figure out what the possible issue may be?  I don't even know what to ask my help desk so I can figure out if the issue is the way the account is set up.  Please advise.

Thank you

Question by:DMUM
  • 2
  • 2
  • 2
  • +1
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35135706
I have used this routine with Redemption to send via Outlook without security dialogs and to a specific account that is not the default account.

You can find Redemption (free) here:

Public Enum tOutlookBodyFormat
   OutlookBodyFormat_Plain = 1
End Enum

Public Sub SendOutlookMailWithRedemption( _
      ByVal ToRecipients As Variant, _
      ByVal Subject As String, _
      ByVal Body As String, _
      Optional ByVal BodyFormat As tOutlookBodyFormat, _
      Optional ByVal CCRecipients As Variant, _
      Optional ByVal BCCRecipients As Variant, _
      Optional ByVal ReplyName As String, _
      Optional ByVal ReplyAddress As String, _
      Optional ByVal Attachments As Variant, _
      Optional ByVal AccountName As String _
   #If AuthoringOutlook Then
      Dim RDOSession As RDOSession
      Dim Drafts As RDOFolder
      Dim Message As RDOMail
      Dim Account As RDOAccount
      Dim RDOSession As Object
      Dim Drafts As Object
      Dim Message As Object
      Dim Account As Object
   #End If
   Dim Attachment As Variant
   Dim Tag As Variant
   If Not IsArray(ToRecipients) Then ToRecipients = Array(ToRecipients)
   If Not IsMissing(CCRecipients) Then If Not IsArray(CCRecipients) Then If Len(CCRecipients) > 0 Then CCRecipients = Array(CCRecipients)
   If Not IsMissing(BCCRecipients) Then If Not IsArray(BCCRecipients) Then If Len(BCCRecipients) > 0 Then BCCRecipients = Array(BCCRecipients)
   If Not IsMissing(Attachments) Then If Not IsArray(Attachments) Then If Len(Attachments) > 0 Then Attachments = Array(Attachments)
   Set RDOSession = CreateObject("Redemption.RDOSession")
   Set Drafts = RDOSession.GetDefaultFolder(16) ' olFolderDrafts
   Set Message = Drafts.Items.Add
   With Message
      If Len(AccountName) > 0 Then
         Set Account = RDOSession.Accounts(AccountName)
         .Account = Account
      End If
      .To = Join(ToRecipients, "; ")
      If IsArrayInitialized(CCRecipients) Then .CC = Join(CCRecipients, "; ")
      If IsArrayInitialized(BCCRecipients) Then .BCC = Join(BCCRecipients, "; ")
      .Subject = Subject
      Select Case BodyFormat
         Case OutlookBodyFormat_Plain
            .Body = Body
         Case OutlookBodyFormat_HTML
            .HTMLBody = Body
         Case OutlookBodyFormat_RichText
            Tag = .GetIDsFromNames("{00062008-0000-0000-C000-000000000046}", &H8582) Or 11 ' PT_BOOLEAN
            .Fields(Tag) = True
            .RTFBody = Body
      End Select
      If IsArrayInitialized(Attachments) Then
         For Each Attachment In Attachments
            If Len(Attachment) > 0 Then .Attachments.Add Attachment
         Next Attachment
      End If
   End With

End Sub

LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35135718
You will need this support routine:

Public Function IsArrayInitialized( _
      ByVal SourceArray As Variant _
   ) As Boolean

' Return True if the array is initialized, False otherwise.

   Dim UpperBound As Long

   UpperBound = -1
   On Error Resume Next
   UpperBound = UBound(SourceArray)
   On Error GoTo 0
   IsArrayInitialized = UpperBound > -1

End Function

LVL 59

Expert Comment

by:Chris Bottomley
ID: 35136050
Stupid question but you have restarted outlook with the three accounts pre-existing?

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35138199
Hello.  Thank u all for responding to my question so quickly.

Chris.  Yes, I have rebooted..restarted outlook and my machine.  I have had at least 2 of the mailboxes for over 2 years.  The one I need to use has just been recently created for this project.  Thanks

Kevin,  I saw a few blurps about redemption when I was looking for a resolution to this issue..didn't realize it was an add in.  I have to see if I can install.  Does this mean all my users will need to install as well.  If so, this may not be a valid fix.  My company hates non-company installed software and most people have locked down pc.  I will still check it out though.  Do you know of anything besides redemption?  Also I will try out your routine, but can you tell me what it is suppose to do?  Thanks.  

LVL 59

Expert Comment

by:Chris Bottomley
ID: 35138760
The two accounts .. you can send emails from each of them from the same instance of outlook, and what version are you using.

I ask only because I use this mechanism myself to select sender in macros and the substance you depict is the same as Use, and I have tested in outlook 2007 your exact code with no issues.

If I recall the accounts method was a 2007 inititiate so if you are using anything earlier this would expain the issue ... assuming errors are being skipped.


Accepted Solution

DMUM earned 0 total points
ID: 35162400
Hi, I fixed the issue by setting up the Account as a POP3.  The problem seems to be caused by us using Microsoft Exchange and any mailboxes that you have access to are still seen in Outlook as a one account when you go to the "Account Settings" window.  Now that I created a new account the code now works fine.  I'd prefer not to do it this way since I need to tell 900 users and growing how to add an email account and management is not particularly happy with this, but if it works with no issues....However, If anyone knows how I can access the mailboxes in my Microsoft Exchange Mailboxes I'd prefer to implement this process using the default set up.  Thanks
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 35744604
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question