smtpServer.start();
final ServerSetup imapSetup = new ServerSetup(2626, "127.0.0.1", ImapConnector.IMAP);
imapServer = new GreenMail(imapSetup);
imapServer.start();
GreenMailUser user = imapServer.getManagers()
.getUserManager()
.createUser("cooling@prancingdonkey.com", "cooling", "password");
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(EMAIL_TEXT);
message.setRecipient(Message.RecipientType.TO, new InternetAddress("cooling@prancingdonkey.com"));
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource("./src/test/resources/cooling.report.pdf") {
@Override
public String getContentType() {
return "application/octet-stream";
}
};
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName("report");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
user.deliver(message);
}