Android Question Sending email


New Member
Hello everyone,
This is my first experience in B4A.
I'm trying to write a code that sends an email.
This is the code I wrote:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'Private x As Int,y As Int,z As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
xui.MsgboxAsync("1", "B4X")
SMTP.Initialize("", 587, "", "xxxxxxx", "SMTP")
SMTP.StartTLSMode = True
SMTP.Subject = "asunto"
SMTP.Body = "cuerpo"
xui.MsgboxAsync("2", "B4X")
End Sub

The compilation goes through without errors but the email is not sent.
For testing, I wrote in a print line before and after sending the email. When you run the app, something strange happens: the second print happens first, followed by the first print.
Can anyone help me fix the code so that the email will be sent?


Nicola Ciaramellano

Licensed User
the code is correct, but the email is blocked from gmail because you have to change (in your google account) the option that pemits to send email from unsecure apps.
Anyway it's not a good idea to send email with gmail using the simple SMTP protocol, because Gmail will not permit it at all in the future.
So, it's better to use GMAIL API:
or change the Email Server or, better than all, use your own email server.
Hope this helps
Last edited:
Upvote 0