I've implemented a simple emailer in my current project using SMTP. It works perfectly whether I send a single email or multiple ones (one after another with customized content) automatically. However, when sending multiple emails, I'd like to receive the MessageSent results of any Send before moving on to sending the next email, so that I can update status of each sent email in a database before continuing with the next one. This is proving to be extremely frustrating, probably because I don't have a good understanding of how MessageSent works.
Here are the basics of my emailing code:
The idea of the 'Do Until' loop in SendEmail is to make it wait until Success has reported a result before SendEmail returns to my UI (where it will be called again with data for the next email). What happens in reality is that it becomes an endless loop because SendStatus is never altered by MessageSent. Can anyone tell me why?
Here are the basics of my emailing code:
B4X:
Sub Process_Globals
Dim SMTP As SMTP
Dim SendStatus As String
End Sub
Sub SendEmail
... (set all the usual SMTP fields)
SendStatus=""
SMTP.Send
Do Until SendStatus<>""
DoEvents
Loop
End Sub
Sub SMTP_MessageSent(Success As Boolean)
If Success=False Then
SendStatus="Failed"
Else
SendStatus="OK"
End If
End Sub
The idea of the 'Do Until' loop in SendEmail is to make it wait until Success has reported a result before SendEmail returns to my UI (where it will be called again with data for the next email). What happens in reality is that it becomes an endless loop because SendStatus is never altered by MessageSent. Can anyone tell me why?