本文整理汇总了Java中com.icegreen.greenmail.util.ServerSetupTest.SMTP_IMAP属性的典型用法代码示例。如果您正苦于以下问题:Java ServerSetupTest.SMTP_IMAP属性的具体用法?Java ServerSetupTest.SMTP_IMAP怎么用?Java ServerSetupTest.SMTP_IMAP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.icegreen.greenmail.util.ServerSetupTest
的用法示例。
在下文中一共展示了ServerSetupTest.SMTP_IMAP属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReceive
@Test
public void testReceive() throws MessagingException, IOException {
//Start all email servers using non-default ports.
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
//Use random content to avoid potential residual lingering problems
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
MimeMessage message = createMimeMessage(subject, body, greenMail); // Construct message
GreenMailUser user = greenMail.setUser("[email protected]", "waelc", "soooosecret");
user.deliver(message);
assertEquals(1, greenMail.getReceivedMessages().length);
// --- Place your retrieve code here
} finally {
greenMail.stop();
}
}
示例2: testSend
@Test
public void testSend() throws MessagingException, IOException {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
//Use random content to avoid potential residual lingering problems
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
sendTestMails(subject, body); // Place your sending code here
//wait for max 5s for 1 email to arrive
//waitForIncomingEmail() is useful if you're sending stuff asynchronously in a separate thread
assertTrue(greenMail.waitForIncomingEmail(5000, 2));
//Retrieve using GreenMail API
Message[] messages = greenMail.getReceivedMessages();
assertEquals(2, messages.length);
// Simple message
assertEquals(subject, messages[0].getSubject());
assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());
//if you send content as a 2 part multipart...
assertTrue(messages[1].getContent() instanceof MimeMultipart);
MimeMultipart mp = (MimeMultipart) messages[1].getContent();
assertEquals(2, mp.getCount());
assertEquals("body1", GreenMailUtil.getBody(mp.getBodyPart(0)).trim());
assertEquals("body2", GreenMailUtil.getBody(mp.getBodyPart(1)).trim());
} finally {
greenMail.stop();
}
}
示例3: testSend
@Test
public void testSend() throws MessagingException {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP); //uses test ports by default
try {
greenMail.start();
GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "some subject",
"some body"); //replace this with your test message content
assertEquals("some body", GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
} finally {
greenMail.stop();
}
}
示例4: testSendTextEmailTest
@Test
public void testSendTextEmailTest() throws Exception {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.setUser("[email protected]", "pwd");
greenMail.start();
GreenMailUtil.sendTextEmail("\"Foo, Bar\" <[email protected]>", "\"Bar, Foo\" <[email protected]>",
"Test subject", "Test message", ServerSetupTest.SMTP);
greenMail.waitForIncomingEmail(1);
Store store = greenMail.getImap().createStore();
store.connect("f[email protected]", "pwd");
try {
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.getMessages();
assertTrue(null != msgs && msgs.length == 1);
Message m = msgs[0];
assertEquals("Test subject", m.getSubject());
Address a[] = m.getRecipients(Message.RecipientType.TO);
assertTrue(null != a && a.length == 1
&& a[0].toString().equals("\"Foo, Bar\" <[email protected]>"));
a = m.getFrom();
assertTrue(null != a && a.length == 1
&& a[0].toString().equals("\"Bar, Foo\" <[email protected]>"));
assertTrue(m.getContentType().toLowerCase()
.startsWith("text/plain"));
assertEquals("Test message", m.getContent());
} finally {
store.close();
}
} finally {
greenMail.stop();
}
}
示例5: testSetAndGetQuota
@Test
public void testSetAndGetQuota() throws MessagingException {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
final GreenMailUser user = greenMail.setUser("[email protected]", "pwd");
Store store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
Quota testQuota = new Quota("INBOX");
testQuota.setResourceLimit("STORAGE", 1024L * 42L);
testQuota.setResourceLimit("MESSAGES", 5L);
assertEquals(0, GreenMailUtil.getQuota(user, testQuota.quotaRoot).length);
GreenMailUtil.setQuota(user, testQuota);
final Quota[] quota = GreenMailUtil.getQuota(user, testQuota.quotaRoot);
assertEquals(1, quota.length);
assertEquals(2, quota[0].resources.length);
store.close();
} finally {
greenMail.stop();
}
}
示例6: testGetEmptyBodyAndHeader
@Test
public void testGetEmptyBodyAndHeader() throws Exception {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
String subject = GreenMailUtil.random();
String body = ""; // Provokes https://github.com/greenmail-mail-test/greenmail/issues/151
String to = "[email protected]";
final byte[] gifAttachment = {0, 1, 2};
GreenMailUtil.sendAttachmentEmail(to, "[email protected]", subject, body, gifAttachment,
"image/gif", "testimage_filename", "testimage_description",
greenMail.getSmtp().getServerSetup());
greenMail.waitForIncomingEmail(5000, 1);
try (Retriever retriever = new Retriever(greenMail.getImap())) {
MimeMultipart mp = (MimeMultipart) retriever.getMessages(to)[0].getContent();
BodyPart bp;
bp = mp.getBodyPart(0);
assertEquals(body, GreenMailUtil.getBody(bp).trim());
assertEquals(
"Content-Type: text/plain; charset=us-ascii\r\n" +
"Content-Transfer-Encoding: 7bit",
GreenMailUtil.getHeaders(bp).trim());
bp = mp.getBodyPart(1);
assertEquals("AAEC", GreenMailUtil.getBody(bp).trim());
assertEquals(
"Content-Type: image/gif; name=testimage_filename\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"Content-Disposition: attachment; filename=testimage_filename\r\n" +
"Content-Description: testimage_description",
GreenMailUtil.getHeaders(bp).trim());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
GreenMailUtil.copyStream(bp.getInputStream(), bout);
assertArrayEquals(gifAttachment, bout.toByteArray());
}
} finally {
greenMail.stop();
}
}