Outlook automation - SendUsingAccount readonly?

P

Pavel Celba

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 = CREATEOBJECT("Outlook.Application")
oNamespace = oOutlook.GetNameSpace("MAPI")
oNamespace.Logon()
loItem = oOutlook.CreateItem(0)
loitem.To = '(e-mail address removed)'
loitem.Body = "BODY"

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

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

Note: If I would send the message now, it will use default account

*-- 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?

I'll test above code in VB.NET to avoid VFP interoperability problem.

TIA for answers!

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

Ken Slovak - [MVP - Outlook]

SendUsingAccount is null until it is set. If you don't set that property the
default account is used. Set the property and that property is used and you
can then retrieve it as non-null.

Try running the VBA Help example from the Object Browser and see how it
works. Just substitute something like this line for the Send() line:

Debug.Print oMail.SendUsingAccount.SmtpAddress
 
M

Miguel Santos

I think you are choosing the wrong user account.
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



Pavel Celba wrote:

Outlook automation - SendUsingAccount readonly?
31-Mar-10

Hi experts

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

My code (Visual FoxPro)
oOutlook = CREATEOBJECT("Outlook.Application"
oNamespace = oOutlook.GetNameSpace("MAPI"
oNamespace.Logon(
loItem = oOutlook.CreateItem(0
loitem.To = '(e-mail address removed)
loitem.Body = "BODY

*-- Here is the proble
loitem.SendUsingAccount = oOutlook.Session.Accounts.Item[2] && I am sur
this is valid POP3 accoun

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

Note: If I would send the message now, it will use default accoun

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

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

I will test above code in VB.NET to avoid VFP interoperability problem

TIA for answers

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

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Circular Progress Indicator
http://www.eggheadcafe.com/tutorial...a-cc047643fd42/wpf-circular-progress-ind.aspx
 
P

Pavel Celba

Thanks for the reply.

VB.NET code works fine for me, so this is problem between Visual FoxPro and
Outlook which means "problem forever"...

Or do you have some work around how to set the SendUsingAccount from Foxpro
via automation?

P.C.



Ken Slovak - said:
SendUsingAccount is null until it is set. If you don't set that property
the default account is used. Set the property and that property is used
and you can then retrieve it as non-null.

Try running the VBA Help example from the Object Browser and see how it
works. Just substitute something like this line for the Send() line:

Debug.Print oMail.SendUsingAccount.SmtpAddress




Pavel Celba said:
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 = CREATEOBJECT("Outlook.Application")
oNamespace = oOutlook.GetNameSpace("MAPI")
oNamespace.Logon()
loItem = oOutlook.CreateItem(0)
loitem.To = '(e-mail address removed)'
loitem.Body = "BODY"

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

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

Note: If I would send the message now, it will use default account

*-- 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?

I'll test above code in VB.NET to avoid VFP interoperability problem.

TIA for answers!

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

Pavel Celba

Thanks for the reply.

I am sure the account is correct, Visual FoxPro just does not allow its
storing into SendUsingAccount property for whatever reason.

I've been testing similar code in VB.NET and it works correctly.

P.C.


in message
news:[email protected]...
 
K

Ken Slovak - [MVP - Outlook]

I don't program in FoxPro and haven't in over 15 years, so I have no idea
about that. I do know that in VBA code the property value is null and cannot
be retrieved unless you explicitly set the property. Then it can be
retrieved. Setting it should be no problem at all, even in FoxPro, as it's a
COM language. But if there's something weird with FoxPro then a FoxPro forum
might be the place to ask.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top