Android Question Multiple eMail

luke2012

Well-Known Member
Licensed User
Longtime User
I'm trying to report the result of multiple mail send.
So I'm using a map where I keep track of mail subject and the Success flag (SMTP_MessageSent event).

My Sub execute multiple sends :

Sub SendMails ()
SendMail1() : CurrentMailSubject="mail1"
SendMail2() : CurrentMailSubject="mail2"
SendMail3() : CurrentMailSubject="mail3"
End Sub

*CurrentMailSubject is a Global var

The SendMail sub reside in a code module and execute a SMTP.Send method.
My target is to track the success for each send to report it to the user.

To do this, I'm populating the map within the "SMTP_MessageSent" event :

Sub SMTP_MessageSent(Success As Boolean)
MyMap.Put(CurrentMailSubject,Success)
End Sub

At the end of all sends I expect that the map was been populated for each mail sent with the related Success flag.

This doesn't happen and I have only the last mail sent result in the map.
I don't understand why.

Any suggestions ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The mails are sent in the background (asynchronously). This means that the code execution doesn't block.

You will need to send the mails differently.
1. Create a List with the mails you need to send.
2. Create a sub that takes the first mail from the list and sends it.
3. In MessageSent event you should remove the first item from the list and call the sub from step #2 again (unless the list is empty).

Note that the time to deliver the messages will be exactly the same as SMTP handles messages one after another (however it happens in the background).
 
Upvote 0
Top