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 43
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
I am not sure what you want but the SendUsingAccount property is NOT readonly

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.
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

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 OzConnect With a Mentor Software 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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.