当前位置: 首页>>代码示例>>Java>>正文


Java GreenMailUtil.createTextEmail方法代码示例

本文整理汇总了Java中com.icegreen.greenmail.util.GreenMailUtil.createTextEmail方法的典型用法代码示例。如果您正苦于以下问题:Java GreenMailUtil.createTextEmail方法的具体用法?Java GreenMailUtil.createTextEmail怎么用?Java GreenMailUtil.createTextEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.icegreen.greenmail.util.GreenMailUtil的用法示例。


在下文中一共展示了GreenMailUtil.createTextEmail方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMail

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
private void sendMail(final String to,
                      final String from,
                      final String subject,
                      final String msg,
                      final ServerSetup serverSetup) throws MessagingException {
    final Session session = GreenMailUtil.getSession(serverSetup);
    final MimeMessage textEmail = GreenMailUtil.createTextEmail(to, from, subject, msg, serverSetup);
    final Transport transport = session.getTransport(serverSetup.getProtocol());
    transport.connect();
    transport.sendMessage(textEmail, new Address[] {new InternetAddress(to)});
    try {
        transport.close();
    } catch (final MessagingException e) {
        //ignore
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:ConcurrentCloseIT.java

示例2: testDatesCorrect

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testDatesCorrect() throws MessagingException, IOException {
    String to = "[email protected]";
    greenMail.setUser(to, to);

    // Create mail with specific 'sent' date
    final MimeMessage mail = GreenMailUtil.createTextEmail(to, "[email protected]", "Subject", "msg", greenMail.getSmtp().getServerSetup());
    final Date sentDate = new GregorianCalendar(2000, 1, 1, 0, 0, 0).getTime();
    mail.setSentDate(sentDate);
    GreenMailUtil.sendMimeMessage(mail);

    greenMail.waitForIncomingEmail(5000, 1);

    retrieveAndCheck(greenMail.getPop3(), to, sentDate, false);
    retrieveAndCheck(greenMail.getImap(), to, sentDate, true);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:DateTest.java

示例3: testUidSearchTextWithCharset

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testUidSearchTextWithCharset() throws MessagingException, IOException {
    greenMail.setUser("[email protected]", "pwd");
    store.connect("[email protected]", "pwd");
    try {
        IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);

        final MimeMessage email = GreenMailUtil.createTextEmail("[email protected]", "[email protected]",
                "some subject", "some content",
                greenMail.getSmtp().getServerSetup());

        String[][] s = {
                {"US-ASCII", "ABC", "1"},
                {"ISO-8859-15", "\u00c4\u00e4\u20AC", "2"},
                {"UTF-8", "\u00c4\u00e4\u03A0", "3"}
        };

        for (String[] charsetAndQuery : s) {
            final String charset = charsetAndQuery[0];
            final String search = charsetAndQuery[1];

            email.setSubject("subject " + search, charset);
            GreenMailUtil.sendMimeMessage(email);

            // messages[2] contains content with search text, match must be case insensitive
            final byte[] searchBytes = search.getBytes(charset);
            final Argument arg = new Argument();
            arg.writeBytes(searchBytes);
            Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() {
                @Override
                public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
                    return protocol.command("UID SEARCH CHARSET " + charset + " TEXT", arg);
                }
            });
            IMAPResponse response = (IMAPResponse) ret[0];
            assertFalse(response.isBAD());
            String number = response.getRest();
            assertEquals(charsetAndQuery[2], number);
        }
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:45,代码来源:ImapProtocolTest.java

示例4: createSimpleMessage

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
private MimeMessage createSimpleMessage() {
  return GreenMailUtil.createTextEmail(
      USERNAME, "[email protected]", "subject", "body", greenMail.getImap().getServerSetup());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:5,代码来源:MailIT.java

示例5: createMimeMessage

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
private MimeMessage createMimeMessage(String subject, String body, GreenMail greenMail) {
    return GreenMailUtil.createTextEmail("[email protected]", "[email protected]", subject, body, greenMail.getImap().getServerSetup());
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:4,代码来源:ExampleReceiveNoRuleTest.java

示例6: createMimeMessage

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
private MimeMessage createMimeMessage() {
    return GreenMailUtil.createTextEmail("[email protected]", "[email protected]", "subject", "body", greenMail.getImap().getServerSetup());
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:4,代码来源:ExampleReceiveTest.java

示例7: testForwardWithRfc822

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
/**
 * Structure of test message and content type:
 * <p>
 * Message (multipart/mixed)
 * \--> MultiPart (multipart/mixed)
 * \--> MimeBodyPart (message/rfc822)
 * \--> Message (text/plain)
 */
@Test
public void testForwardWithRfc822() throws MessagingException, IOException {
    greenMail.setUser("[email protected]", "pwd");
    final Session session = greenMail.getSmtp().createSession();

    // Message for forwarding
    Message msgToBeForwarded = GreenMailUtil.createTextEmail(
            "[email protected]", "[email protected]", "test newMessageWithForward", "forwarded mail content",
            greenMail.getSmtp().getServerSetup());


    // Create body part containing forwarded message
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setContent(msgToBeForwarded, "message/rfc822");

    // Add message body part to multi part
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);

    // New main message, containing body part
    MimeMessage newMessageWithForward = new MimeMessage(session);
    newMessageWithForward.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
    newMessageWithForward.setSubject("Fwd: " + "test");
    newMessageWithForward.setFrom(new InternetAddress("[email protected]"));
    newMessageWithForward.setContent(multipart);   //Save changes in newMessageWithForward message
    newMessageWithForward.saveChanges();

    GreenMailUtil.sendMimeMessage(newMessageWithForward);

    final IMAPStore store = greenMail.getImap().createStore();
    store.connect("[email protected]", "pwd");
    try {
        Folder inboxFolder = store.getFolder("INBOX");
        inboxFolder.open(Folder.READ_WRITE);
        Message[] messages = inboxFolder.getMessages();
        MimeMessage msg = (MimeMessage) messages[0];
        assertTrue(msg.getContentType().startsWith("multipart/mixed"));
        Multipart multipartReceived = (Multipart) msg.getContent();
        assertTrue(multipartReceived.getContentType().startsWith("multipart/mixed"));
        MimeBodyPart mimeBodyPartReceived = (MimeBodyPart) multipartReceived.getBodyPart(0);
        assertTrue(mimeBodyPartReceived.getContentType().toLowerCase().startsWith("message/rfc822"));

        MimeMessage msgAttached = (MimeMessage) mimeBodyPartReceived.getContent();
        assertThat(msgAttached.getContentType().toLowerCase(), startsWith("text/plain"));
        assertArrayEquals(msgToBeForwarded.getRecipients(Message.RecipientType.TO), msgAttached.getRecipients(Message.RecipientType.TO));
        assertArrayEquals(msgToBeForwarded.getFrom(), msgAttached.getFrom());
        assertEquals(msgToBeForwarded.getSubject(), msgAttached.getSubject());
        assertEquals(msgToBeForwarded.getContent(), msgAttached.getContent());
    } finally {
        store.close();
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:61,代码来源:Rfc822MessageTest.java


注:本文中的com.icegreen.greenmail.util.GreenMailUtil.createTextEmail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。