1. Chris Waldron
  2. PowerBuilder
  3. Wednesday, 13 May 2020 21:29 PM UTC

I'm converting an old VB6 app to PB and I'm encountering a problem converting code that utilizes a 3rd-party tool called OSSMTP to send automated emails.  I can convert the code to enable sending of the email from PB, but I can't capture an error when one occurs.

Here's the OSSMTP object model:  http://ostrosoft.com/ossmtp/ossmtp_reference.aspx

In VB6, there's a concept called Dim WithEvents that can be declared as follows:

Dim WithEvents oSMTP As OSSMTP.SMTPSession

Then we can define our SendMail method:

Private Sub SendEmail()

On Error GoTo EH_SendEmail

DoEvents '*** needed to ensure email logic does not conflict with modals ***

Set oSMTP = New OSSMTP.SMTPSession

With oSMTP
.Server = ???
.Port = ???
.AuthenticationType = ???
.UserName = ???
.Password = ???
.UseSSL = ???
.MailFrom = ???
.ReplyTo = ???
.SendTo = ???
.CC = ???
.BCC = ???
.MessageSubject = ???
.MessageText = ???
.Importance = 0
.Notification = 0
.Sensitivity = 0

'Send the email.
.SendEmail
End With

Set oSMTP = Nothing

Exit Sub

EH_SendEmail:
Call goError.GeneratedMessage(Error$, CLASS_NAME & "->SendEmail")

If Not oSMTP Is Nothing Then
Set oSMTP = Nothing
End If
End Sub

And finally the custom event that gets triggered when there's an error:

Private Sub oSMTP_ErrorSMTP(ByVal Number As Integer, Description As String)
Dim sMessage As String
sMessage = "Unable to send the automated " & m_sEmailType & " e-mail!"
sMessage = sMessage & vbCrLf & vbCrLf & "Please report the following information to the Service Desk:"
sMessage = sMessage & vbCrLf & vbCrLf & "Error " & Number & ": " & Description
MsgBox sMessage, vbCritical + vbOKOnly, App.Title
'MsgBox "Error " & Number & ": " & Description, vbCritical + vbOKOnly, App.Title
End Sub

There doesn't seem to be any equivalent to Dim WithEvents in Powerbuilder.

I've tried to implement it using TRY ... CATCH blocks with exception/runtimeerror/oleruntimeerror objects, but nothing seems to work. (see attached file)

I feel like I'm missing something really basic, but I can't seem to figure out what that is.

Has anyone done anything similar where they can offer some advice?

Attachments (1)
Chris Waldron Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 18:24 PM UTC
  2. PowerBuilder
  3. # 1

Thanks Roland!  I'll download it later today and give it a try.

Comment
  1. Roland Smith
  2. Saturday, 16 May 2020 02:47 AM UTC
A PBX file is really a DLL so the same rules apply. Place it in the same folder as the EXE or somewhere in the path.

The source code download link is there on the same page below "Complete Visual Studio 2017 solution folder".

No, there is no documentation.
  1. Helpful
  1. Chris Waldron
  2. Saturday, 16 May 2020 19:43 PM UTC
I never even noticed the other link. I'll downlink the source and take a look. Thanks again for all your help!
  1. Helpful
  1. John Fauss
  2. Saturday, 16 May 2020 20:00 PM UTC
Chris - There's some documentation from Appeon regarding the PowerBuilder Native Interface (PBNI) here:

https://docs.appeon.com/appeon_online_help/pb2019r2/native_interface_programmers_guide_and_reference/index.html

  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 17:44 PM UTC
  2. PowerBuilder
  3. # 2

I have two SMTP solutions on my website, I would try this one:

https://www.topwizprogramming.com/pbnismtp.html

 

Comment
There are no comments made yet.
Chris Waldron Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 15:48 PM UTC
  2. PowerBuilder
  3. # 3

I'm open to anything at this point.  I'll download the source and take a look.  Thanks John!

Comment
  1. Chris Pollach @Appeon
  2. Tuesday, 19 May 2020 18:51 PM UTC
Hi Chris;

Another good alternative ... https://www.example-code.com/powerbuilder/smtp.asp

Regards .... Chris
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 15:12 PM UTC
  2. PowerBuilder
  3. # 4

Greetings, Chris - 

Instead of trying to fit a square peg (OSSMTP) into a round hole (PB), are you open to the idea of an alternative SMTP/PB interface?

If so, I suggest you look at the EmailSMTP free code sample provided by Roland Smith at his TopWizProgramming.com web site:

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

Roland's code interfaces to an SMTP server via WinSock API calls - so it's all WinAPI calls, no third-party DLL.

Regards, John

Comment
There are no comments made yet.
Chris Waldron Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 13:44 PM UTC
  2. PowerBuilder
  3. # 5

Thanks for the suggestion Miguel!  As soon as I read it, it seemed so obvious that this would give me what I needed.

Unfortunately, it didn't work.  I did just what you suggested, but neither the ERROR nor the EXTERNALEXCEPTION events were triggered.

This is incredibly frustrating.  Any other suggestions would be welcome.

Comment
  1. Miguel Leeuwe
  2. Thursday, 14 May 2020 18:09 PM UTC
It was worth trying, but sorry to hear it didn't work.
  1. Helpful
  1. Chris Waldron
  2. Thursday, 14 May 2020 18:48 PM UTC
No worries Miguel! You're right that it was worth testing and I should have known to use this approach myself. Thanks for your help!
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 10:56 AM UTC
  2. PowerBuilder
  3. # 6

My suggestion, not sure if it'll show you the errors:

 

You'll get 2 error events which you might be able to debug/code, if you create a new object: "standard class", select "oleobject" from the list and save that as for example: n_oo

then instead of declaring  

"oleobject iOLEServer"

you declare

n_oo iOLEServer
int li_ret

iOLEServer = Create n_oo
li_ret = iOLEServer.ConnectToNewObject("OSSMTP.SMTPSession") 
....

...... whatever you're doing

.....

iOLEServer.DisConnectobject()
destroy iOLEServer

return

You'll have an "error" and "externalException" event where you might be able to check on what's happening when errors occur.

If you want to deal with any errors in those events, here's some example for externalexception:

string ls_source, ls_description

ls_source = source
ls_description = description
if isnull(ls_source) then ls_source = ""
if isnull(ls_description) then ls_description = ""

ls_description = (ls_description + " - " + ls_source)
//gnv_app.of_debug( ls_description )

Messagebox("Error", ls_description)

action = ExceptionIgnore!

It's worth trying if those events are fired when there's an error.

regards

Comment
There are no comments made yet.
Chris Waldron Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 04:57 AM UTC
  2. PowerBuilder
  3. # 7

There is no ActiveX version of this COM object.

Comment
There are no comments made yet.
Ricardo Jasso Accepted Answer Pending Moderation
  1. Thursday, 14 May 2020 01:09 AM UTC
  2. PowerBuilder
  3. # 8

Chris,

If it were an ActiveX control PowerBuilder will automatically handle the link between the third party control's events and the OleCustomControl control. I've done it with a third party FTP object where I wanted to insert code in the OnProgress event to update a progress bar. If the control you mention has an ActiveX version of it you could do it this way.

Regards,

Ricardo

 

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.