attachment.setPath(testFile.getAbsolutePath());
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setName("Test_Attachment");
attachment.setDescription("Test Attachment Desc");
final MockMultiPartEmailConcrete testEmail =
new MockMultiPartEmailConcrete();
testEmail.setHostName(this.strTestMailServer);
testEmail.setSmtpPort(this.getMailServerPort());
testEmail.setFrom(this.strTestMailFrom);
testEmail.addTo(this.strTestMailTo);
testEmail.attach(attachment);
testEmail.setSubType("subType");
if (EmailUtils.isNotEmpty(this.strTestUser)
&& EmailUtils.isNotEmpty(this.strTestPasswd))
{
testEmail.setAuthentication(
this.strTestUser,
this.strTestPasswd);
}
testEmail.setSubject(strSubject);
testEmail.setMsg("Test Message");
final Map<String, String> ht = new HashMap<String, String>();
ht.put("X-Priority", "2");
ht.put("Disposition-Notification-To", this.strTestMailFrom);
ht.put("X-Mailer", "Sendmail");
testEmail.setHeaders(ht);
testEmail.send();
this.fakeMailServer.stop();
// validate message
validateSend(
this.fakeMailServer,
strSubject,
testEmail.getMsg(),
testEmail.getFromAddress(),
testEmail.getToAddresses(),
testEmail.getCcAddresses(),
testEmail.getBccAddresses(),
true);
// validate attachment
validateSend(
this.fakeMailServer,
strSubject,
attachment.getName(),
testEmail.getFromAddress(),
testEmail.getToAddresses(),
testEmail.getCcAddresses(),
testEmail.getBccAddresses(),
false);
// ====================================================================
// Test Exceptions
// ====================================================================