Android Question SMTP runs fine on Android 10, but not on Andorid 11 (First Post)

LGS

Member
Licensed User
Longtime User
Hello everyone.

I need to use SMTP to send emails from a specific corporate email.
In Android 10, everything runs fine even with attachments.
But in Android 11, no mail is sent even with just text

In the manifest:
B4X:
android:targetSdkVersion="29"

B4X:
Private Sub Button1_Click
    If IsEmail(correo.Text.trim) = True Then
        Dim smtp As SMTP
        smtp.Initialize("smtp.gmail.com", 465, "[email protected]", "xxxxx", "smtp")
        smtp.UseSSL = True
        smtp.To.Add(correo.Text)
        smtp.Subject = "Desde App"
        smtp.Body = "Correo Enviado"
        Wait For (smtp.Send) SMTP_MessageSent(Success As Boolean)
        If Success Then
            xui.MsgboxAsync("Correo enviado","Ok")
        Else
            xui.MsgboxAsync("No se envió","Oh oh")
        End If
    Else
        ToastMessageShow("Correo inválido",True)
    End If
End Sub

Sub IsEmail(EmailAddress As String) As Boolean
    Dim MatchEmail As Matcher = Regex.Matcher("^(?i)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$", EmailAddress)
    If MatchEmail.Find = True Then
        Return True
    Else
        Return False
    End If
End Sub


If anyone has used SMTP on Android 11, I would appreciate the support 🤝
 

Attachments

  • Project.zip
    14.1 KB · Views: 100
  • Permisos.png
    Permisos.png
    3.7 KB · Views: 109

LGS

Member
Licensed User
Longtime User
Hi Erel, thank you for your support


Logs:
Registro conectado a:  motorola motorola one vision
--------- beginning of main
Copying updated assets files (1)
* Service (starter) Create *
* Service (starter) Start *
* Activity (main) Create, isFirst = true *
* mainpage: B4XPage_Created
* mainpage: B4XPage_Appear
* Activity (main) Resume *
false, (RuntimeException) java.lang.RuntimeException: Empty writer returned: 530-5.7.0 Authentication Required. Learn more at
530 5.7.0  https://support.google.com/mail/?p=WantAuthError w20sm1273633vkw.28 - gsmtp
 
Upvote 0

LGS

Member
Licensed User
Longtime User
Yes, initially I had to allow "less secure apps" in order to send emails.

This is checked
 

Attachments

  • Acceso.png
    Acceso.png
    4.7 KB · Views: 115
Upvote 0

LGS

Member
Licensed User
Longtime User
Using a corporate email, everything works fine on Android 11.

Apparently, in addition to accepting "less secure apps" Google has other restrictions (for Android 11) that I could not find.

On devices with Android 10, using the gmail account, the app sends emails without problems

For now, the solution is to use a corporate account.
 
Upvote 0

LGS

Member
Licensed User
Longtime User
As I wrote, it has nothing to do with Android 11.
I've just tested it and it works.

Google does block new devices for security reasons. I needed to reenable "less secure apps" to make it work.
Thanks Erel, you are right, this error has nothing to do with Android 11

I have tried with different devices (Android 8,10,11) connected by wifi (Ip where I requested "less secure apps") and all the devices work without problem. But when disconnecting the wifi and using the operator's connection (Another IP), the App does not send email and gives the error of post # 3
If the device reconnects to Wi-Fi, it works fine again.

Google allows the App only to be used by devices connected to the IP where I requested "less secure apps" ?

That is what is happening in this case...
 
Upvote 0
Top