我正在尝试从我的应用程序发送电子邮件进行注册。它包含一个随机数,需要输入该号才能激活帐户。但我无法弄清楚如何用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
谢谢!
答案 0 :(得分:0)
更改
if(passwordBox.getText() == confirmPasswordBox.getText())
到
if(passwordBox.getText().toString().equals(confirmPasswordBox.getText().toString()))