Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send otp via email from my Android app for signup & verification

I have tried to use the email sending method for sending a random number as otp to the email addresses- BUT this only works on the devices that installed app dirctly from android studio BUT the devices which installed the generated apk cannot send the emails I used the normal email sending code for sending the otp..(But the email sending only works on the device that installed the app directly from android studio..

Random rand = new Random();
        n = rand.nextInt(55320) + 1;

        rec = reciep.getText().toString();
        ml = rec;
        subject = "Your OTP FOR app";
        textMessage = "YOUR OTP IS ->" + n;

        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        session = Session.getDefaultInstance(props, new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("myemail", "mypassword");
            }
        });

        pdialog = ProgressDialog.show(context, "", "Sending OTP...", true);

        RetreiveFeedTask task = new RetreiveFeedTask();
        task.execute();

    }
}
like image 315
Achy97 Avatar asked Nov 24 '25 12:11

Achy97


1 Answers

Go on google and turn on less secure app https://myaccount.google.com/lesssecureapps

like image 72
zinonX Avatar answered Nov 27 '25 01:11

zinonX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!