[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


SendUsingAccount not working - code not finding Mailbox Accounts

Posted on 2011-03-15
Medium Priority
Last Modified: 2012-05-11
Hi, I've attempted to use the code from rondrebruin.nl 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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: http://www.dimastr.com/redemption/

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?

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal


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
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

650 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