String to="mydaman7291@gmail.com";//change accordingly
//Get the session object
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 sess = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("daman.bonnie07@gmail.com","password");//change accordingly
}
});
//compose message
try {
MimeMessage message = new MimeMessage(sess);
message.setFrom(new InternetAddress("daman.bonnie07@gmail.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello");
message.setText("Testing.......");
//send message
Transport.send(message);
System.out.println("message sent successfully");
}
catch (MessagingException e) {
out.println(e);}
メールの送信中に次のエラーが表示されます
javax.mail.MessagingException: 例外読み取り応答。ネストされた例外は次のとおりです: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX パスの構築に失敗しました: sun.security.provider.certpath.SunCertPathBuilderException: 要求されたターゲットへの有効な証明書パスが見つかりません