cancel
Showing results for 
Search instead for 
Did you mean: 

Sending emails using OLE

Former Member
0 Kudos

PB 12.1 and 12.5

Outlook 2007/2010

Win XP and 7

Having issues sending emails automatically from application. Code developed in the 90's no longer works. MSDN documentation seems to indicate it should so I'm guessing I'm doing something wrong in Powerbuilder.

Basically the mailitem.Display and mailitem.Send functions trigger a runtime exception saying unable to access.

I've replaced mailitem.Display to...

   inspector.mailitem.GetInpector

   inspector.Activate

It works great.

I cannot find a Send alternative. Anyone familiar with this? I know my target audience is limited so please respond only if your familiar with OLE and Outlook interop.

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks to all for the input. Based on the information and testing my conclusion is as follows:

Powerbuilder now has limited mail integration capabilities using Outlook 2007 and higher. Code that works accessing Outlook 2003 on XP now fails in Outlook 2007 and higher on XP/7. This is due to security enhancements made by Microsoft and Sybase has not updated its methods to maintain a native interface.

Former Member
0 Kudos

Hi Guys.

My environment is:

PowerBuilder 10.5.2 build 7757

Windows 7-64 bits

MS Office Outlook 2010-64 bits

Using the code sent by Abdallah, I got the same error when sending a message as reported by Russel when the MS Outlook is closed.

I put the line "ole_item.Display" before the line "ole_item.Send" and it works fine with the MS Outlook opened or closed.

I hope it helps.

Cheers,

Luiz

Former Member
0 Kudos

I use OLE with Outlook 2010 on W7-64 and XP and it works fine.  I don't have the automated send function.

I've attached my user object.  Maybe it will help you.

former_member190719
Active Contributor
0 Kudos

In addition to what Roland suggested, I have a utility that does SMTP via PBNI:

https://pbnismtp.codeplex.com/

As well as a sample of doing it through .Net (look for SMPTClient.zip).

http://goo.gl/VXouQ

You can use SMTP to send mail through the exchange server that Outlook talks to.

Former Member
0 Kudos

Bruce,

SMTP is not authorized in my environment. Can I code and implement it. Sure. Am I supposed to no. When I have time I will check if I can even access it. I don't think it will work because of our security certificates.

The only reason I'm sending mails from the client is I have one database which is not authorizing Oracle mail because it is classified. They requested Outlook so that they can have the option of sign/encrypt. If they dont need to do that I send mail automatically. Or atleast I'm trying to.

I wont use MAPI because of the security errors it causes Outlook to display.

Former Member
0 Kudos

Have a look at this :

http://support.microsoft.com/kb/2298962

Abdallah.

Former Member
0 Kudos

My account settings say mail is being delivered to my exchange inbox. Dialogs don't look that on my machine and there is no change button available for me. But I dont see a problem.

former_member190719
Active Contributor
0 Kudos

SMTP is not authorized in my environment.

Actually, I'm a bit suprised by that.  Outlook has it's own set of issues, I'm not sure I would consider it necessarily more secure than SMTP provided that the SMTP server is sufficently hardened.

We've got apps deployed in very high security environments and we are allowed to use SMTP.  One major difference though is that we don't send it from our client.  We store the email message information in the database and have the database send the email using it's own capability.  That means the SMTP server admin only needs to authorize that server to send email, not every single client station. 

Former Member
0 Kudos

I've done it that way too, add a row to a table that is specifically designed to hold emails. A server side batch job then sends the emails. It is also much faster, especially if the app has to send multiple emails.

Former Member
0 Kudos

Bruce,

People holding the reigns don't want to give them up. Had to fight for UTL_MAIL and scheduled jobs. SMTP just won't happen. I am fully aware this is maybe the 5th most desirable solution but I have to pick my battles.

Roland - A method similar to what you describe was presented to me and I denied it. My emails contain what is called "personal identifiable information". Which exposes me to all find of security and encryption mandates just to send a silly email. I share this only so you know I was thorough in going the Outlook road.

former_member190719
Active Contributor
0 Kudos

FWIW, when our email contains PII we have a stored procedure that sends the email immedaitely rather than store the record in the database.  Understand about the problems getting UTL_MAIL authorized though.

Former Member
0 Kudos

I have a comprehensive package developed that performs various tasks and calls utl_mail to send messages. For my site which will not turn on Oracle mail due to regulations I put a stub out there and return the PII back to the client for sending the mail. Eventually they will realize that there "security" requirement is actually less secure and require an encrypted database connection. That is just one of my OAS motivations from the other thread.

Former Member
0 Kudos

Hi,

I tested your code and just added ole_item.Send() and it works for me.

HTH.

Abdallah.

Former Member
0 Kudos

I tried that too after looking at Roland's code. He has a mailitem.Delete( ) in his sample so I added ( ). Both crashed.

Former Member
0 Kudos

Here is your code changed. just put it in a button.

I have OutLook running and I uncommented the ole.Quit() which closes my Outlook.


boolean i_b_ShowMessage = false
integer retval, li_AttachmentCount, li_AttachmentItem, li_OutlookVersion=0
string ls_CurVer, ls_temp
OLEObject ole_outlook, ole_item, ole_attach, ole_recipient, ole_inspector

RegistryGet("HKEY_CLASSES_ROOT\Outlook.Application\CurVer", "", RegString!, ls_CurVer)

ls_temp = RIGHT( ls_CurVer, 2 )
if IsNumber( ls_temp ) then li_OutlookVersion = integer( ls_temp )
mle_mail.text = ls_CurVer
ole_outlook = Create OLEObject

TRY
ole_outlook.ConnectToNewObject( ls_CurVer )

//Creates a new mail Item
ole_item = ole_outlook.CreateItem( 0 ) //Microsoft.Office.Interop.Outlook.MailItem

ole_item.Subject  = sle_sub.text
ole_item.Body   = mle_mail.text
ole_item.To = "abdallah.elrhazoui@zzzzzzzz.com"

if i_b_ShowMessage then
  ole_inspector = ole_item.GetInspector
  ole_inspector.Activate
else
  // Send the message
  ole_item.Send()
end if

catch (RuntimeError exception )
  messagebox( "Unable to send email.", "An internal has prevented the email from being sent.~r~n~r~n" +&
      "Please contact support with the following information:~r~n"+&
      "~tError Number: " + string( exception.number ) + "~r~n" +&
      "~tObject: " + string( exception.class ) + "~r~n" +&
      "~tFunction: " + string( exception.routinename ) + "~r~n" +&
      "~tLine: " + string( exception.line ) + "~r~n" +&
      "~tDescription: " + string( exception.text ),&
     stopsign! )
  return -1
FINALLY
// clean-up the session
//ole_outlook.Quit( )
ole_outlook.DisconnectObject( )
END TRY

Former Member
0 Kudos

Exact code crashes on Send( ) for me.

Former Member
0 Kudos

........ and it works fine for me :

Windows 7 64 bits.

I could remember there were some problems and there is some Microsoft patches to install.

I'll do further research an let you know if I find something.

I also tested with MAPI and it works for me.

Best Regards.

Abdallah.

Former Member
0 Kudos

I'm testing on XP. Will try on Win 7 32.

Former Member
0 Kudos

Do you have 64bit Outlook? PB is 32bit so will only work with 32bit Outlook.

Former Member
0 Kudos

No 64 bit in my shop

Former Member
0 Kudos

As I wrote earlier, your code works fine for me with Outlook *32

Cheers.


Abdallah.

Former Member
0 Kudos

which version of Outlook and PB are you?

Former Member
0 Kudos

Outlook 2010 32 bits

PB 12.5.2

Windows 7 64 bits

Cheers.

Abdallah.

Former Member
0 Kudos

Must assume something different in 64 bit then but that doesn't make sense. Since I will never use 64 at work I have to stick with my "conclusion". Thanks for the feedback.

Former Member
0 Kudos

You should try using SMTP instead. It bypasses Outlook, your app will communicate directly with your mail server.

http://www.topwizprogramming.com/freecode_emailsmtp.html

Former Member
0 Kudos

Roland,

Outlook is my requirement. I cannot access SMTP directly due to regulations.

Former Member
0 Kudos

I have an example of connecting to Outlook via OLE. It displays the contents of your InBox. The page has a link to the Outlook Object Model. I'm sure there is the ability to send email.

http://www.topwizprogramming.com/freecode_outlook.html

Former Member
0 Kudos

Roland,

This code crashes as well. Appears methods and properties of the mail item are unresolvable. Yours is crashing on sendername.

I'm ready to open a support ticket with SAP unless you tell me I'm way off.

Former Member
0 Kudos

Hi Russ;

   The problem is that Sybase never enhanced the "simple" MAPI functionality in PB to support the newer "extended" MAPI specification. So that is why PB's internal Mail commands are useless today. I suspect that Roland's example is also SimpleMAPI based. So when your system turns on higher security levels or demands ExtendedMAPI to be used - your application crashes.

   FWIW: You can contact SAP about ExtendedMAPI and/or SMTP support in PB - but, since we cannot even get whether SAP will enhance PB (not official until its in SAP's price book); if/when PB 15 will be worked on (never mind released); etc - I don't think your mail problem will be resolved soon (unfortunately).

  BTW: ExtendedMAPI support and native SMTP support have been in PB's enhancement list for years <sigh> .... http://my.isug.com/p/cm/ld?fid=187

Regards ... Chris

Former Member
0 Kudos

Chris,

His code is using  OLEObject and mailitem properties and methods just like mine.

Former Member
0 Kudos

Hi Russ;

   Yes, its the same thing ... SimpleMAPI.

  MS placed security rules around SimpleMAPI in more recent MS-Office versions to ward off Spamming - so you need to either use ExtendedMAPI or SMTP (neither of which PB supports natively).

Regards ... Chris

Former Member
0 Kudos

Thanks. I just will not support direct messages. Reinventing a new interface is out of scope. The user will have to view the message manually and click Send.

Former Member
0 Kudos

Chris,

My EmailSMTP example is true SMTP using Winsock API functions directly to communicate with the mail server. It is not MAPI based. My Outlook example reads the Inbox using OLE but does not have code to send email. The Outlook OLE example's download page has a link to Microsoft's documentation of the Outlook OLE interface which would document how to send email via OLE.

Roland

Former Member
0 Kudos

Hi Roland;

   Yes, I know. Your "add-on" code is great!  

  I was talking about PB natively supporting ExtendedMAPI and SMTP. These features have been asked for many times in the past - but, Sybase just kept ignoring the PB community's enhancement requests.

Regards ... Chris