Outlook automation - SendUsingAccount readonly?

Hi experts,

I am trying to change the default Outlook account but it seems to be readonly for new mail messages... Does somebody know the solution?

My code (Visual FoxPro):
oOutlook = CREATE("Outlook.Application")
oNamespace = oOutlook.GetNameSpace("MAPI")
loItem = oOutlook.CreateItem(0)
loitem.To = 'some@email.com'
loitem.Body = "BODY"

*-- Here is the problem
loitem.SendUsingAccount = oOutlook.Session.Accounts.Item[2]  && I am sure this is POP3 account

*-- Account should be changed now BUT
? loitem.SendUsingAccount   && Still returns null (it is not an object)

*-- After issuing
*-- and changing Account manually via UI everything works as it should - means the SendUsingAccount property is no more Readonly and I can assign different accounts via automation commands...

So, the question is: How to create mail item having the SendUsingAccount property R/W using automation?


Outlook version: 2007 SP2 (12.0.6514.5000)
OS version: Vista SP2

VB.NET zone added to meet more experts.
LVL 44
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I am not sure what you want but the SendUsingAccount property is NOT readonly


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pcelbaAuthor Commented:
I know it is advertised as RW and it behaves like RW under certain circumstances (as described in my question) but did you try the code from above link? Does it work for you?
pcelbaAuthor Commented:
Hmm, it seems the problem is in VFP - Outlook interoperabiliyty... The VB.NET code works correctly.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

The Interop Assemblies are same. I have not used the property myself. I use From address to change that if the user has the permissions to SendAs in exchange.
Miguel OzSoftware EngineerCommented:
I will check if you are assigning the right account. Remember that:
is a one-based array collection.
The "2" in a zero based array means the third element, but in the item array means picking the second account.
Thus if you are trying to access the third account in the item array you need:

pcelbaAuthor Commented:
No, this is really not the problem.

VFP can even display all properties from this accounts collection but it cannot assign the account object to SendUsingAccount property before its manual "initialization".
pcelbaAuthor Commented:
It seems this problem has no direct solution. Anyway, thanks for your contributions!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.