1. damian jimenez
  2. PowerBuilder
  3. Tuesday, 19 March 2024 15:48 PM UTC

Trying SMTPClient object with Powerbuilder 2022R2 build 2819  in Windows 10

i create some function to to send email sync and async and work aawesome,
but i had a trouble to check  responses to the sending async.. i had some questions

Question 1

-------------
in description https://docs.appeon.com/pb2022r3/powerscript_reference/OnSendFinished_event.html

In description said: Occurs when an email is sent by SendAsync. If there is an error from SendAsync, this event gets the error number and error text.

and in the list of error number:

The return error number. Returns 1 if sending email succeeds and one of these negative numbers if it fails.

  • 1 -- Success.                 ( can i get errornumber = 1      ??)

  • -1 -- A general error occurred.

  • -2 -- Unable to connect to service through proxy.

  • -3 -- Couldn’t resolve proxy. The given proxy host could not be resolved.

  • -4 -- Couldn’t resolve host. The given remote host could not be resolved.

  • -5 -- Failed to connect to host.

  • -6 -- Host using bad/illegal format or missing host.

  • -7 -- ...................................

Alwais get errornumber or only if there is an error like said in description ?
(in this case never get errornumber 1 )

Question 2

------------

I can´t get response from OnSendFinished event,
maybe i´am doing something wrong ..
i create an object inherit from SMTClient and add log file in OnSendFinished event, but  the file  is never written
i attached a word file.

thanks a lot people

 

Attachments (1)
Accepted Answer
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 20 March 2024 04:28 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Damian,

#1: Regarding the return value of the OnSendFinished Event.

This event only triggers during asynchronous sending, and it always triggers. During local testing, if the sending is successful, the value of ErrorNumber is 1. I suggest writing its value to a control within this event, which would help tracking. For example:

w_email.mle_log.text += 'On Send Finished Event: Handle =' + String(Handle) + ', Number= ' + String(ErrorNumber) + ', Text = ' + ErrorText + '~r~n'

 

#2: Regarding the Event ID of the OnSendFinished event.

The Event ID of this OnSendFinished event is (None), which is normal.

 

#3: Regarding the OnSendFinished event not triggering during asynchronous sending.

1) Please use smtpclient.SendAsync() function to send emails.

2) According to the Help documentation, even if you set smtpclient.LogFile(string filepath), it will not write to this specified log file during asynchronous sending. You need to manually write error information to the target file or output it to a window control within the OnSendFinished event. For example:

w_email.mle_log.text += 'On Send Finshed Event: Handle =' + String(Handle) + ', Number= ' + String(ErrorNumber) + ', Text = ' + ErrorText + '~r~n'

3) After inheriting the SMTPClient Object, I recommend declaring it as a global variable and not immediately destroying it after sending the email. This prevents the SMTPClient object from being destroyed before the OnSendFinished event triggers asynchronously.

4) Additionally, I suggest upgrading to PB 2022 R2 2828 or PB 2022 R3 and try it again.

5) If you still encounter issues, I suggest that you submit a bug through our Support Portal and attach your small case source code (pbl and pbt files) so that we can better track and analyze this issue.

 

Regards,

Ken

Comment
There are no comments made yet.
damian jimenez Accepted Answer Pending Moderation
  1. Thursday, 21 March 2024 15:04 PM UTC
  2. PowerBuilder
  3. # 1

Hi ken

#1: Regarding the return value of the OnSendFinished Event.

ok, i fill that info in two variables, and shows at end of sending (see video attached)

#2: Regarding the Event ID of the OnSendFinished event.

Ok, perfect, thank you very much

 

#3: Regarding the OnSendFinished event not triggering during asynchronous sending.


  1) Yes, I'm using Sendasync
   2) Ok, I'm going to remove it from log, but also wrote the value in an array and not stores anything
  3) Yes, it is declared globally
4) I had Updated to Build 2828 and the same thing it happens, I must work with this version yet, that's why I am based on the respective documentation. can´t change to 202R3 yet
5) It is very difficult to send a small piece of code, and generally it is not the same, i ´ll send a video with attached the source shown in the video (Window and Object) in text format. May be helps.

I POST A NEW QUESTION BECAUSE NO LET ME SEND HERE, A LETER WITH "Please enter a title for your discussion" AND DN´T LET ME RESPONSE
thank you so much

Comment
There are no comments made yet.
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Friday, 22 March 2024 02:45 AM UTC
  2. PowerBuilder
  3. # 2

Hi Damian,

Based on the video you provided, there seems to be a design issue in your code, as shown in the attached screenshot:
Your n2_smtp object inherits from smtpclient, and you have written code in the OnSendFinished event of n2_smtp to capture the return value.
However, when you call the SendAsync function, you are using the n2_smtpclient object, which is an SMTPClient object, not n2_smtp object. Therefore, it will not trigger the OnSendFinished event of the n2_smtp object.

I suggest you try modifying it as follows:
1. In the Instance Variables of n2_smtp, delete code SMTPClient n2_smtpClient.
2. Replace all the “n2_smtpClient.” in the n2_smtp object with “This.” and save it.
3. When other places need to use the n2_smtp object to send emails, I suggest you declare it as Global Variable or Instance Variable and do not immediately destroy it after sending the emails.

 

 

Regards,

Ken

Comment
There are no comments made yet.
damian jimenez Accepted Answer Pending Moderation
  1. Friday, 22 March 2024 11:21 AM UTC
  2. PowerBuilder
  3. # 3

Awesome Ken, thak you, my object was wrong, thank you so much !!

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.