on 09-20-2013 9:41 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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).
You can use SMTP to send mail through the exchange server that Outlook talks to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.
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.
Hi,
I tested your code and just added ole_item.Send() and it works for me.
HTH.
Abdallah.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You should try using SMTP instead. It bypasses Outlook, your app will communicate directly with your mail server.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.