Outlook automation - SendUsingAccount readonly in VFP...?

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

My code:
oOutlook = CREATEOBJECT("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)

loItem.Send()  && sends the message to default account address

*-- 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?
Subquestion is: Does it work same (wrong) way for you in VFP?


Similar code executed from VB.NET works correctly... (see e.g. http://msdn.microsoft.com/en-us/library/bb207787.aspx)

Thanks for all responses
LVL 43
pcelbaAsked:
Who is Participating?
 
mikegagnonConnect With a Mentor Commented:
oNamespace.Logon() has parameters. Use it to logon with the profile you want
to use.
0
 
rr_milesCommented:
Outlook configuration can be scripted via VFP. Checkout

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")

' 3  Deleted Items
' 4  Outbox
' 5  Sent Items
' 6  Inbox
' 9  Calendar
'10  Contacts
'11  Journal
'12  Notes
'13  Tasks
'16  Drafts
'18  All Public Folders

for i = 0 to 20
  Set ofChosenFolder = mynamespace.GetDefaultFolder(i)
  print i, "  ", ofchosenfolder
next
0
 
pcelbaAuthor Commented:
Hmm, thanks. How this could help to solve my problem?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rr_milesCommented:
If I understand what you are doing, you want to create a new Outlook Account for sending. Since you have already created the account on your test machine, you want to be able to create the account on another machine? Try scripting Outlook by using the Registry. A good example is http://vbnet.mvps.org/index.html?code/reg/regoutlookaccounts.htm
0
 
rr_milesCommented:
BTW, my Outlook ref lists;

MailItem.SendUsingAccount Property
Outlook Developer Reference
Returns or sets an Account object that represents the account under which the MailItem is to be sent. Read/write.

0
 
pcelbaAuthor Commented:
Yes, I would like to assign value (account object reference) to SendUsingAccount property.

The problem is this property is read/only when accessed from VFP using automation (see code sample in my question). Based on all MSFT descriptions and articles this property is never r/o.

So, I would like to know how to do it. Does some work around exist?
0
 
rr_milesCommented:
I think you may need to go behind Outlook and use the registry. Did you look at the link http://vbnet.mvps.org/index.html?code/reg/regoutlookaccounts.htm ?
0
 
rr_milesCommented:
I think you may need to go behind Outlook and use the registry. Did you look at the link http://vbnet.mvps.org/index.html?code/reg/regoutlookaccounts.htm ?
0
 
pcelbaAuthor Commented:
I have the account info available in FoxPro already. The  oOutlook.Session.Accounts  collection contains all accounts and they are correct. The account I am trying to assign is valid POP3 account.

Anyway, thanks for the link, the VB code may be useful.
0
 
rr_milesCommented:
BTW; POP3 is for recieving email and SMTP is for sending email.
0
 
rr_milesCommented:
BTW; POP3 is for recieving email and SMTP is for sending email.
0
 
pcelbaAuthor Commented:
:-)  Do you have separate accounts for sending and receiving in your Outlook?

It could also mean Microsoft is doing it wrong in this example: http://msdn.microsoft.com/en-us/library/bb207787.aspx
0
 
rr_milesCommented:
Yes. My Outlook setup page reads "Incoming mail server: (POP3)" and "Outgoing mail server (SMTP)". Some IPSs may combine them, but my experience is that many do not. I also find the “Test account settings” button very helpful for troubleshooting. I use Microsoft Office 2003. My laptop is dual boot Vista and XP. Regarding Microsoft, it would not be the first time. Many times I find examples on the Internet better than MSDN examples.
 
0
 
pcelbaAuthor Commented:
Hmm, are you able to set just Outgoing mail server and leave the Incoming one empty in your Outlook?
0
 
rr_milesCommented:
Interesting idea. I will try it using only one.
0
 
pcelbaAuthor Commented:
Any news how to make SendUsingAccount read/write in VFP?
0
 
pcelbaAuthor Commented:
Finally, I have to say this is the only working solution.
0
All Courses

From novice to tech pro — start learning today.