// hostname not set
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.send();
fail("Should have thrown an exception");
}
catch (EmailException e)
{
this.fakeMailServer.stop();
assertTrue(true);
}
// bad hostname
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.setSubject("Test Email #1 Subject");
this.email.setHostName("bad.host.com");
this.email.setFrom("me@home.com");
this.email.addTo("me@home.com");
this.email.addCc("me@home.com");
this.email.addBcc("me@home.com");
this.email.addReplyTo("me@home.com");
this.email.setContent(
"test string object",
" ; charset=" + EmailConstants.US_ASCII);
this.email.send();
fail("Should have thrown an exception");
}
catch (EmailException e)
{
assertTrue(e.getCause() instanceof ParseException);
this.fakeMailServer.stop();
assertTrue(true);
}
// ====================================================================
// Test Exceptions (in send)
// ====================================================================
// from add not set
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.setHostName(this.strTestMailServer);
this.email.setSmtpPort(this.getMailServerPort());
this.email.send();
fail("Should have thrown an exception");
}
catch (EmailException e)
{
this.fakeMailServer.stop();
assertTrue(true);
}
// destination (to/cc/bcc) dd not set
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.setHostName(this.strTestMailServer);
this.email.setSmtpPort(this.getMailServerPort());
this.email.setFrom("me@home.com");
this.email.send();
fail("Should have thrown an exception");
}
catch (EmailException e)
{
this.fakeMailServer.stop();
assertTrue(true);
}
// bad auth set
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.setHostName(this.strTestMailServer);
this.email.setSmtpPort(this.getMailServerPort());
this.email.setFrom(this.strTestMailFrom);
this.email.addTo(this.strTestMailTo);
this.email.setAuthentication(null, null);
this.email.send();
fail("Should have thrown an exception");
}
catch (EmailException e)
{
this.fakeMailServer.stop();
assertTrue(true);
}
// validate that the correct smtp port is visible in the exception message
// in case ssl connection is used
try
{
this.getMailServer();
this.email = new MockEmailConcrete();
this.email.setHostName("bad.host.com");
this.email.setSSLOnConnect(true);
this.email.setFrom(this.strTestMailFrom);
this.email.addTo(this.strTestMailTo);
this.email.setAuthentication(null, null);