B4J Question [ABMaterial]: [SOLVED] Using ResumableSub??

Mashiane

Expert
Licensed User
Longtime User
Hi there

Has anyone tried to use a ResumableSub inside ABMaterial?

I have just converted my SendEmail subroutine to use ResumableSub to no avail using the jnet 1.77 library.

For some reason my app never goes beyong the Wait For statement.

B4X:
Sub SendEmail(toEmail As String, subject As String, msg As String) As ResumableSub
    'Try
        'read the email settings first
        Dim es As Map = GetEmailSettings
        Dim sserver As String = es.GetDefault("server","")
        Dim sport As String = es.GetDefault("port","25")
        Dim susername As String = es.GetDefault("username","")
        Dim spassword As String = es.GetDefault("password","")
        Dim sStartTLSMode As String = es.GetDefault("starttlsmode","0")
        Dim sUseSSL As String = es.GetDefault("usessl","0")
        'start sending the email
        esmtp.Initialize(sserver, sport, susername, spassword, "smtp")
        esmtp.To.Add(toEmail)
        esmtp.Body = msg
        esmtp.Subject = subject
        If sStartTLSMode = "1" Then
            esmtp.StartTLSMode = True
        Else
            esmtp.StartTLSMode = False
        End If
        If sUseSSL = "1" Then
            esmtp.UseSSL = True
        Else
            esmtp.UseSSL = False
        End If
        Wait For (esmtp.Send) smtp_MessageSent(Success As Boolean)
        Return Success
    'Catch
    '    Return False
    'End Try
End Sub

This is based on this article here which was showing a way to send emails using smtp inside an ABMaterial app. If I remove the wait for and just use .send, it runs, any ideas please?

NB: The same code in a normal b4j app works perfectly.

Thanks
 

Cableguy

Expert
Licensed User
Longtime User
My guess is the send method does not return anything so the wait for just sits there... Waiting
 
Upvote 0

mindful

Active Member
Licensed User
Has anyone tried to use a ResumableSub inside ABMaterial?
ABmaterial is just a UI part. It takes code from b4j and converts it to html and js - nothing more - and communicatiates with B4J server app via websockets. If your code works inside a b4j server app then it will work on one which is using ABMaterial. I am using smtp with wait for and it works but I have a background worker class where i declared the smtp object.

Whitout seeing more code from you I can't pin point the exact problem, but I can see that you declared the SendEmail sub as Resumable Sub. how are you handling the return of this ? Do you want to notify the user if the email has been sent ? Are you waiting for the sub to complete ? something like this :
B4X:
Dim rs As ResumableSub = SendEmail("[email protected]", "test", "test")
Wait For (rs) Complete (Result as Boolean)
The above code waits for the SendEmail sub to finish and returns the result - without it is all async.
 
Upvote 0
Top