I need to send an email using the client settings. Host access uses STARTTLS security using port 587.
For testing I put the following code (I changed the client data for security):
try {
String host = "200.201.202.203";
String port = "587";
String address = "[email protected]";
String pass = "xxxx";
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.quitwait", "false");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", address);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", port);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(address));
Multipart multiPart=new MimeMultipart();
InternetAddress toAddress = new InternetAddress("[email protected]");
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject("Send Auto-Mail");
message.setContent(multiPart);
message.setText("Demo For Sending Mail in Android Automatically");
Transport transport = session.getTransport("smtp");
transport.connect(host, address, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
} catch (Exception e) {
Log.e(this.getClass().toString(), e.getMessage());
return false;
}
However when trying to connect on the host (transport.connect ()) the following error occurs:
javax.mail.MessagingException: Could not convert socket to TLS; nested exception is: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
I think it's some missing property (or not), but I'm not sure how to handle that mistake. What to do in this case?
I did the same test using lib javamail but I got the same error: link