1

我正在尝试从我的应用程序发送一封电子邮件以进行注册。它包含一个随机数,需要输入该随机数才能激活帐户。但我不知道如何在 Java 中做到这一点。

我试过这个:

public void registerButtonMethod(View view){
        if(usernameBox.getText().length() > 2)
        {
             if(passwordBox.getText() == confirmPasswordBox.getText())
             {
                String adress = emailBox.getText().toString();
                int randomzahl = (int) ((Math.random()*pMaximum)+1);
                String host = "smtp.gmail.com";
                String from = adress;
                String pass = password;
                Properties props = System.getProperties();
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.host", host);
                props.put("mail.smtp.user", from);
                props.put("mail.smtp.password", pass);
                props.put("mail.smtp.port", "587");
                props.put("mail.smtp.auth", "true");

                String[] to = {emailBox.getText().toString()};
                Session session = Session.getDefaultInstance(props, null);
                MimeMessage message = new MimeMessage(session);
                message.setFrom(new InternetAddress(from));
                InternetAddress[] toAddress = new InternetAddress[to.length];
                message.setSubject("test");
                message.setText("test");
                Transport transport = session.getTransport("smtp");
                transport.connect(host, from, pass);
                transport.sendMessage(message, message.getAllRecipients());
                transport.close();
            }
        }
}

但我认为这行不通:/我很高兴能得到你们的帮助:D

谢谢!

4

1 回答 1

0

改变

if(passwordBox.getText() == confirmPasswordBox.getText())

if(passwordBox.getText().toString().equals(confirmPasswordBox.getText().toString()))
于 2013-07-29T16:55:11.843 回答