简体   繁体   English

从我的 Android 应用程序通过电子邮件发送 otp 以进行注册和验证

[英]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..我尝试使用电子邮件发送方法将随机数作为 otp 发送到电子邮件地址-但这仅适用于从 android studio 直接安装应用程序的设备,但安装生成的 apk 的设备无法发送我使用的电子邮件用于发送 otp 的普通电子邮件发送代码..(但电子邮件发送仅适用于直接从 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();

    }
}

继续谷歌并打开不太安全的应用程序https://myaccount.google.com/lesssecureapps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM