B4J Question ServletResponse has ended when calling SMTP.Send

aeric

Expert
Licensed User
Longtime User
I tried to use ServletResponse.Write but the ServletResponse has already ended once I called SMTP.Send.
How can I use ServletResponse.Write to return a Response text after the SMTP completed?

Line #16 and #19 have no effect.
B4X:
Response.Write("EmailTest is running...")
LogDebug("Sending email...")
SMTP.Sender = SMTP_USERNAME
SMTP.To.Add(ADMIN_EMAIL)
SMTP.AuthMethod = SMTP.AUTH_LOGIN
SMTP.HtmlBody = True
SMTP.subject = "Message from B4J mail"
SMTP.body = $"<strong>EMAIL TEST SUCCESS</strong>
    <hr>
    Email is sent from ${Main.ROOT_URL}<br/>
    The current time here is: ${DateTime.Time(DateTime.Now)}"$
'SMTP.Send
Wait For (SMTP.Send) SMTP_MessageSent (Success As Boolean)
If Success Then
    LogDebug("Message sent successfully")
    Response.Write("Message sent successfully")
Else
    LogDebug("Error sending message")
    Response.Write("Error sending message")
End If
 

Attachments

  • SMTP.zip
    2.8 KB · Views: 312

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top