Solved

SendUsingAccount not working - code not finding Mailbox Accounts

Posted on 2011-03-15
8
1,845 Views
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

0
Comment
Question by:DMUM
  • 2
  • 2
  • 2
  • +1
8 Comments
 
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
   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
 
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

Kevin
0
 
LVL 59

Expert Comment

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

Chris
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:DMUM
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.  

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

Chris
0
 

Accepted Solution

by:
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
0
 
LVL 50

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
If you don't know how to downgrade, my instructions below should be helpful.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now