这是我的代码:
private void jb_emailActionPerformed(java.awt.event.ActionEvent evt) {
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 = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("my_email@gmail.com","mypassword");
}
}
);
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("my_email@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("my_recepient@gmail.com"));
message.setSubject("hi this is me");
message.setText("hi!");
Transport.send(message);
JOptionPane.showMessageDialog(null,"message sent to your email");
}catch(Exception e){
System.out.append(e.getMessage());
}
}
每当我点击按钮时,它都会显示如下错误:
534 5.7.14 https://support.google.com/mail/answer/78754 rs8sm2429742pbb.14 - gsmtp 534-5.7.14请通过网络浏览器登录 534-5.7.14然后再试一次。 534-5.7.14了解更多信息 534 5.7.14 https://support.google.com/mail/answer/78754 dh1sm2432432pbd.49 - gsmtp
非常感谢任何帮助!