按下按钮时,我正在使用java邮件发送自动邮件。
我在android studio上工作,我收到错误javax.mail.AuthenticationFailedException
,我找不到原因。
这是代码:
Properties props = new Properties();
props.put("mail.smtp.host" , "smtp.gmail.com");
props.put("mail.stmp.user" , "horiond@gmail.com");
//TLS
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.password", "xxxxx");
//SSL
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 = Session.getDefaultInstance( props , null);
String to = "horiond@gmail.com";
String from = "horiond@gmail.com";
String subject = "Testing...";
Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress(to));
msg.setSubject(subject);
msg.setText("Working fine..!");
Transport transport = session.getTransport("smtp");
transport.connect("smtp.gmail.com" , 465 , "horiov@gmail.com", "xxxx");
transport.send(msg);
System.out.println("fine!!");
}
catch(Exception exc) {
System.out.println(exc);
}
答案 0 :(得分:0)
您可以在另一个问题中查看此链接。这应该可以帮助你。
Sending Email in Android using JavaMail API without using the default/built-in app