use of com.zimbra.cs.mailclient.smtp.SmtpConfig in project zm-mailbox by Zimbra.
the class TestSmtpClient method testMimeMessage.
@Test
public void testMimeMessage() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(USER2_NAME);
// Assemble the message.
MimeMessage mm = new ZMimeMessage(JMSession.getSession());
InternetAddress addr = new JavaMailInternetAddress(TestUtil.getAddress(USER_NAME));
mm.setFrom(addr);
mm.setRecipient(RecipientType.TO, addr);
String subject = NAME_PREFIX + " testMimeMessage";
mm.setSubject(subject);
mm.setText("testMimeMessage");
mm.saveChanges();
// Initialize SMTP client.
SmtpConfig config = new SmtpConfig(mHost, mPort, "localhost");
SmtpConnection conn = new SmtpConnection(config);
conn.sendMessage(mm);
// Make sure it arrived.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
// Send the same message to a different envelope recipient.
conn.sendMessage(addr.getAddress(), new String[] { TestUtil.getAddress(USER2_NAME) }, mm);
mbox = TestUtil.getZMailbox(USER2_NAME);
TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
}
use of com.zimbra.cs.mailclient.smtp.SmtpConfig in project zm-mailbox by Zimbra.
the class TestSmtpClient method sendAndVerify.
private void sendAndVerify(String sender, String[] recipients, String subject, String body, String expectedBody) throws Exception {
// Fix up user names and subject.
if (sender.indexOf("@") < 0) {
sender = TestUtil.getAddress(sender);
}
for (int i = 0; i < recipients.length; i++) {
if (recipients[i].indexOf("@") < 0) {
recipients[i] = TestUtil.getAddress(recipients[i]);
}
}
if (subject.indexOf(NAME_PREFIX) < 0) {
subject = NAME_PREFIX + " " + subject;
}
// Send.
String content = new MessageBuilder().withFrom(sender).withToRecipient(recipients[0]).withSubject(subject).withBody(body).create();
SmtpConfig config = new SmtpConfig(mHost, mPort, "localhost");
SmtpConnection smtp = new SmtpConnection(config);
smtp.sendMessage(sender, recipients, content);
// Verify.
for (String recipient : recipients) {
ZMailbox mbox = TestUtil.getZMailbox(recipient);
ZMessage msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
String currentBody = getBodyContent(msg.getMimeStructure());
TestUtil.assertMessageContains(currentBody, expectedBody);
}
}
Aggregations