SendUsingAccount not working - code not finding Mailbox Accounts

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

DMUMAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DMUMConnect With a Mentor Author Commented:
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
0
 
zorvek (Kevin Jones)ConsultantCommented:
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
   OutlookBodyFormat_HTML
   OutlookBodyFormat_RichText
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
   #Else
      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")
   RDOSession.Logon
   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
      .Save
      .Send
   End With

End Sub

Kevin
0
 
zorvek (Kevin Jones)ConsultantCommented:
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

Kevin
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Chris BottomleyCommented:
Stupid question but you have restarted outlook with the three accounts pre-existing?

Chris
0
 
DMUMAuthor Commented:
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.  

0
 
Chris BottomleyCommented:
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.

Chris
0
 
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.