- Local time
- Today, 12:45
- Joined
- Sep 12, 2006
- Messages
- 15,955
I am trying to send emails in VBA by using a gmail account, rather than my default account.
I am using code to loop round my email accounts, but it doesn't display any of the 3 gmail accounts I have added to my outlook account.
It finds 5 POP accounts and an M/S Exchange Account, but it doesn't then show the IMAP accounts, which are the gmail accounts. See the PNG.
I tried changing the order of the gmail accounts to get them above the exchange account just in case, but it skips over them in the debug window.
It works correctly if I choose one the POP accounts as the sender.
I wasn't 100% sure my code was right, and getting to this point needed modification from the downloads I used, but this seems to iterate the collection correctly.
Is there maybe a larger collection than this one? Set olaccounts = MyOutlook.Session.Accounts
Can anyone help please?
Return
I am using code to loop round my email accounts, but it doesn't display any of the 3 gmail accounts I have added to my outlook account.
It finds 5 POP accounts and an M/S Exchange Account, but it doesn't then show the IMAP accounts, which are the gmail accounts. See the PNG.
I tried changing the order of the gmail accounts to get them above the exchange account just in case, but it skips over them in the debug window.
It works correctly if I choose one the POP accounts as the sender.
I wasn't 100% sure my code was right, and getting to this point needed modification from the downloads I used, but this seems to iterate the collection correctly.
Is there maybe a larger collection than this one? Set olaccounts = MyOutlook.Session.Accounts
Can anyone help please?
Code:
select_outlook_account:
'we want to send emails from myemail.sendfrom
Dim olaccounts As Object
Dim olaccountTemp As Object
Dim foundAccount As Boolean
foundAccount = False
Set olaccounts = MyOutlook.Session.Accounts
For Each olaccountTemp In olaccounts
Debug.Print olaccountTemp.smtpAddress
If (olaccountTemp.smtpAddress = MyEmail.sendfrom) Then
foundAccount = True
Set MyMail.sendusingaccount = olaccountTemp
Return
End If
Next
Set olaccountTemp = Nothing
Set olaccounts = Nothing
Return