We use the javamail-android library to send messages via the Gmail SMTP server in our own application.

Everything works fine, but only on those networks in which at least once logged into the appropriate Google account.

If an application tries to send a message from a foreign network (for example, a foreign Wi-Fi access point), the javax.mail.AuthenticationFailedException exception is javax.mail.AuthenticationFailedException .

In account settings, account access for unsafe applications is allowed.

The problem can be solved by providing access to a Google account: https://accounts.google.com/DisplayUnlockCaptcha . But this option is unsafe, because Access data is stored in the application and can be used by hackers.

How to solve this problem without losing account security?

    1 answer 1

    The problem was solved by turning on two-step authentication and using the application password instead of the account password in our application.