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")
oNamespace.Logon()
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
loitem.Display
*-- 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?

TIA

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

VB.NET zone added to meet more experts.
LVL 44
pcelbaAsked:
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.

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

http://msdn.microsoft.com/en-us/library/bb207787.aspx
0

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?
0
pcelbaAuthor Commented:
Hmm, it seems the problem is in VFP - Outlook interoperabiliyty... The VB.NET code works correctly.
0
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.

CodeCruiserCommented:
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.
0
Miguel OzSoftware EngineerCommented:
I will check if you are assigning the right account. Remember that:
oOutlook.Session.Accounts.Item
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:
oOutlook.Session.Accounts.Item[3]

Check:
http://msdn.microsoft.com/en-us/library/bb175024.aspx
0
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".
0
pcelbaAuthor Commented:
It seems this problem has no direct solution. Anyway, thanks for your contributions!
0
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
Programming

From novice to tech pro — start learning today.