Hi Subhrajyoti,
We have used the following code to set the Outlook Account where a user has multiple accounts.
OLEObject lole_item, lole_attach, lole_outlook
string ls_file_name
lole_outlook = Create OLEObject
//Connect to Outlook session using 'Outlook.Application'
long li_rc
li_rc = lole_outlook.ConnectToNewObject("outlook.application")
If li_rc <> 0 Then
// ERROR CONDITION
Messagebox("Outlook Error",string(li_rc))
Destroy lole_outlook
return
else
//Multiple Email Accounts can only be accessed from Outlook using Outlook 2007 or higher.
String ls_default_account
OLEObject lole_accounts,lole_account
long ll_accounts, ll_this_account
ls_default_account = xxx@company.com
If ls_default_account > '' Then
lole_accounts = lole_outlook.session.accounts // get the Outlook "accounts" object
ll_accounts = lole_accounts.count // get the number of accounts in Outlook
// find which account has been selected
For ll_this_account = 1 To ll_accounts
lole_account = lole_accounts.item(ll_this_account) // get an individual "account" object
If lole_account.DisplayName = ls_default_account Then
Exit
End If
Next
If IsNull(iOle_account) Then
MessageBox('Error','Unable to use selected Account')
End If
Else
MessageBox('Error','No default Email Account selected to send the emails')
Destroy lole_outlook
Return
End If
End If
You can then use lole_account to set the default account on the mail item when you are about to send it.
// It will use the default account from Settings
lole_item.SendUsingAccount = lole_account
Hope that helps
Michael