1. Subhrajyoti Ghosh
  2. PowerBuilder
  3. Tuesday, 27 November 2018 14:31 PM UTC

I am sending e-mails using Ole object (outlook.application) . The outlook in my computer is configured with two e-mail addresses. Say, one is xxx@gmail.com and another is xxx@company.com. Here in outlook, the default mail is set as xxx@gmail.com(that can't be changed). The requirement is to send emails from email id xxx@company.com from PB code.

 

Is there any way that I can code so that whenever PB will be sending the mails it will use xxx@company.com and ignore the default one set in outlook i.e xxx@gmail.com

 

I am Using PB 12.6 4091 build.As per the requirement, I have to use Outlook can't ignore Outlook using SMTP.

Any help will be highly appreciated.

Thank You,

Subhrajyoti

 

 

 

John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 27 November 2018 22:08 PM UTC
  2. PowerBuilder
  3. # 1

Are you familiar with the Logon method of the Namespace object? I have not used it, but from the Microsoft documentation it looks like this might be a way to accomplish what you are requesting.

I keep a browser bookmark to the Microsoft documentation regarding the Outlook Object Model:

https://msdn.microsoft.com/en-us/library/bb208225.aspx

The information there has been invaluable in helping me figure out how to use Outlook to send mail via OLE instead of using MAPI.

I hope this helps.

Comment
There are no comments made yet.
Michael Hartnett Accepted Answer Pending Moderation
  1. Wednesday, 28 November 2018 08:46 AM UTC
  2. PowerBuilder
  3. # 2

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

Comment
There are no comments made yet.
Subhrajyoti Ghosh Accepted Answer Pending Moderation
  1. Wednesday, 28 November 2018 13:39 PM UTC
  2. PowerBuilder
  3. # 3

Thanks Michael. This will address the issue.

 

 

Thanks a lot for you advise.

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.