To test if a mail was successfully sent using Java you would normally need an SMTP-server to check. If it happens that you don’t have a server available, you can use mailtrap. To setup mailtrap, following code is used:
Properties prop = new Properties();
prop.put("mail.smtp.auth", true);
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", "smtp.mailtrap.io");
prop.put("mail.smtp.port", "25");
prop.put("mail.smtp.ssl.trust", "smtp.mailtrap.io");
session = Session.getInstance(prop, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("YYY", "XXX");
}
});
Mails sent using this session token end up in webservice that you can check.