I am trying to use GreenMail to test if the code send an email correctly but it seems that GreenMail is not receiving the email.
What am I doing wrong?
Security.setProperty("ssl.SocketFactory.provider",
DummySSLSocketFactory.class.getTypeName());
GreenMail greenMail = new GreenMail(ServerSetup.SMTPS);
greenMail.start();
{
// This is the test subject that I moved here to compact the code
Security.addProvider(new Provider());
Properties props = new Properties();
props.put("mail.smtp.host", "email-smtp.XXX.amazonaws.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("XXX", "XXX");
}
});
session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("XXX@XXX.com"));
message.setRecipients(Message.RecipientType.TO,
new InternetAddress[]{new InternetAddress("XXX@XXX.com")});
message.setSubject("XXX");
message.addHeader("Content-type", "text/html; charset=UTF-8");
message.setContent("XXX", "text/html");
Transport.send(message);
}
assertEquals(greenMail.getReceivedMessages().length, 1);
Aucun commentaire:
Enregistrer un commentaire