DMUM
asked on
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.Appl ication")
For I = 1 To OutApp.Session.Accounts.Co unt
MsgBox OutApp.Session.Accounts.It em(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
Sub Which_Account_Number()
Dim OutApp As Outlook.Application
Dim I As Long
Set OutApp = CreateObject("Outlook.Appl
For I = 1 To OutApp.Session.Accounts.Co
MsgBox OutApp.Session.Accounts.It
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
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
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
Stupid question but you have restarted outlook with the three accounts pre-existing?
Chris
Chris
ASKER
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.
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.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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 SendOutlookMailWithRedempt
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.R
RDOSession.Logon
Set Drafts = RDOSession.GetDefaultFolde
Set Message = Drafts.Items.Add
With Message
If Len(AccountName) > 0 Then
Set Account = RDOSession.Accounts(Accoun
.Account = Account
End If
.To = Join(ToRecipients, "; ")
If IsArrayInitialized(CCRecip
If IsArrayInitialized(BCCReci
.Subject = Subject
Select Case BodyFormat
Case OutlookBodyFormat_Plain
.Body = Body
Case OutlookBodyFormat_HTML
.HTMLBody = Body
Case OutlookBodyFormat_RichText
Tag = .GetIDsFromNames("{0006200
.Fields(Tag) = True
.RTFBody = Body
End Select
If IsArrayInitialized(Attachm
For Each Attachment In Attachments
If Len(Attachment) > 0 Then .Attachments.Add Attachment
Next Attachment
End If
.Save
.Send
End With
End Sub
Kevin