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
 
Ad

Advertisements

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/tutorials/aspnet/4d89b4cb-ba59-4362-ab0a-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:201033118404miguel.santos@nielsen.com...
 
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.
 
Ad

Advertisements

Joined
Sep 23, 2010
Messages
1
Reaction score
0
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
Hello ....

Find the solution using the following statement ....

loOutlook.Session.Accounts.Item(1).SmtpAddress

If you delete the last part of expression (including the dot) and re-type the dot, you can see all the properties and methods of the object , this does not appear in the debug window...... only appears as an object .

Because this behavior? ... I Don't know ... maybe because the debug utility not load the framework of .Net for the outlook object ... but if viewed in the editor VFoxpro.

I hope you serve.

Greetings.

Emilio G. Burgoa
San Juan - Argentina
 

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

Top