KarenLloyd
Programmer
Hello Tek-Tips Gurus
Please can anyone help me with Outlook automation - specifically with making use of a non-default secondary profile?
I'm still using VFP6 (yes!) and have Outlook 2007 for dev/tests - will be 2010 when live.
Initially my two accounts were set up in Outlook and I tried to set the MailItem.SendUsingAccount property to the account object I want - with
myOLApp.Session.Accounts.Item(i)
I know the second account is accessible because my test code puts the DisplayName into the Subject line, yet the emails are still sent from the default account.
So, I moved onto the NameSpace Logon method - but this didn't work for me either.
Next, I changed the email accounts to profiles set up via the control panel, rather than directly in Outlook and I now have IMAP/SMTP profile accounts. I can start Outlook and log in as either user from the dialog window but I still cannot automate the LogOn. Emails always send from the Outlook profile when I open without the dialog prompt, if I select the second profile then, of course, emails send as I want them to.
To further complicate things - when it comes to using the live app, users already have Outlook open on their own profiles. I guess it wouldn't be too much of a problem to sync, force send/recv then close and reopen Outlook if I had to, but that's not ideal.
The objective is for certain emails to be routed thru the 2nd profile, and for users to be able to see sent & recvd without having to log in/out to switch accounts.
Here's a much shortened version of the code
I am obviously missing something, but I'm chasing my tail now.
Any pointers please, oh wise ones?
Karen
Please can anyone help me with Outlook automation - specifically with making use of a non-default secondary profile?
I'm still using VFP6 (yes!) and have Outlook 2007 for dev/tests - will be 2010 when live.
Initially my two accounts were set up in Outlook and I tried to set the MailItem.SendUsingAccount property to the account object I want - with
myOLApp.Session.Accounts.Item(i)
I know the second account is accessible because my test code puts the DisplayName into the Subject line, yet the emails are still sent from the default account.
So, I moved onto the NameSpace Logon method - but this didn't work for me either.
Next, I changed the email accounts to profiles set up via the control panel, rather than directly in Outlook and I now have IMAP/SMTP profile accounts. I can start Outlook and log in as either user from the dialog window but I still cannot automate the LogOn. Emails always send from the Outlook profile when I open without the dialog prompt, if I select the second profile then, of course, emails send as I want them to.
To further complicate things - when it comes to using the live app, users already have Outlook open on their own profiles. I guess it wouldn't be too much of a problem to sync, force send/recv then close and reopen Outlook if I had to, but that's not ideal.
The objective is for certain emails to be routed thru the 2nd profile, and for users to be able to see sent & recvd without having to log in/out to switch accounts.
Here's a much shortened version of the code
Code:
myOLApp = createobject("Outlook.Application")
oNamespace = myOLApp.GetNameSpace("MAPI")
oNamespace.LogOff()
oNamespace.LogOn('proname2',,.F.,.F.)
oMailFolder = oNamespace.GetDefaultFolder(6) && Inbox
oItem = myOLApp.CreateItem(olMailItem)
**.. usual bits for body, attachments etc
* i = cycle thru the accounts to match by parameters
oItem.Subject=myOLApp.Session.Accounts.Item(i).DisplayName && for testing
oItem.SendUsingAccount = myOLApp.Session.Accounts.Item(i)
**..
oItem.Send
**.. sync(?), null, close etc
I am obviously missing something, but I'm chasing my tail now.
Any pointers please, oh wise ones?
Karen