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


Java GreenMailUtil.sendMimeMessage方法代码示例

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


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

示例1: htmlMessage

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

  Session session = greenMail.getSmtp().createSession();
  MimeMessage message = MailTestUtil.createMimeMessageWithHtml(session);

  GreenMailUtil.sendMimeMessage(message);

  PollMailResponse response = MailConnectors.pollMails()
    .createRequest()
      .folder("INBOX")
    .execute();

  List<Mail> mails = response.getMails();
  assertThat(mails).hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getHtml()).isEqualTo("<b>html</b>");
  assertThat(mail.getText()).isEqualTo("text");
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:22,代码来源:PollMailConnectorTest.java

示例2: messageWithAttachment

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void messageWithAttachment() throws Exception {
  File attachment = new File(getClass().getResource("/attachment.txt").toURI());
  assertThat(attachment.exists()).isTrue();

  greenMail.setUser("[email protected]", "bpmn");

  Session session = greenMail.getSmtp().createSession();
  MimeMessage message = MailTestUtil.createMimeMessageWithAttachment(session, attachment);
  GreenMailUtil.sendMimeMessage(message);

  PollMailResponse response = MailConnectors.pollMails()
    .createRequest()
      .folder("INBOX")
    .execute();

  List<Mail> mails = response.getMails();
  assertThat(mails).hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getAttachments()).hasSize(1);

  Attachment mailAttachment = mail.getAttachments().get(0);
  assertThat(mailAttachment.getFileName()).isEqualTo("attachment.txt");
  assertThat(mailAttachment.getPath()).isNotNull();
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:27,代码来源:PollMailConnectorTest.java

示例3: testEscapeMessageID

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testEscapeMessageID() throws MessagingException, IOException {
    String to = "[email protected]";
    String from = "bar`bar <[email protected]>";
    String subject = "Bad IMAP Envelope";
    String body = "Example text";
    greenMail.setUser(to, to);

    Session smtpSession = greenMail.getSmtp().createSession();
    GreenMailMimeMessage mimeMessage = new GreenMailMimeMessage(smtpSession);

    mimeMessage.setRecipients(Message.RecipientType.TO, to);
    mimeMessage.setFrom(from);
    mimeMessage.setSubject(subject);
    mimeMessage.setText(body);

    GreenMailUtil.sendMimeMessage(mimeMessage);
    greenMail.waitForIncomingEmail(5000, 1);

    retrieveAndCheck(greenMail.getImap(), to, from, subject);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:22,代码来源:EscapingTest.java

示例4: 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

示例5: testSendAndWaitForIncomingMailsInBcc

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSendAndWaitForIncomingMailsInBcc() throws Throwable {
    String subject = GreenMailUtil.random();
    String body = GreenMailUtil.random();
    final MimeMessage message = createTextEmail("[email protected]", "[email protected]", subject, body, greenMail.getSmtp().getServerSetup());
    message.addRecipients(Message.RecipientType.BCC, "[email protected],[email protected]");

    assertEquals(0, greenMail.getReceivedMessages().length);

    GreenMailUtil.sendMimeMessage(message);

    assertTrue(greenMail.waitForIncomingEmail(1500, 3));

    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(3, emails.length);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:17,代码来源:SmtpServerTest.java

示例6: testSend

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSend() throws MessagingException, UnsupportedEncodingException {

    Session session = GreenMailUtil.getSession(ServerSetupTest.SMTP, properties);
    MimeMessage mimeMessage = new MockInternationalizedMimeMessage(session);
    mimeMessage.setSubject("subject");
    mimeMessage.setSentDate(new Date());
    mimeMessage.setFrom("múchätįldé@tìldę.oœ");
    mimeMessage.setRecipients(Message.RecipientType.TO, "用户@例子.广告");
    mimeMessage.setRecipients(Message.RecipientType.CC, "θσερεχα@μπλε.ψομ");
    mimeMessage.setRecipients(Message.RecipientType.BCC, "राममो@हन.ईन्फो");

    // The body text needs to be encoded if it contains non us-ascii characters
    mimeMessage.setText(MimeUtility.encodeText("用户@例子"));

    GreenMailUtil.sendMimeMessage(mimeMessage);

    // Decoding the body text to verify equality
    String decodedText = MimeUtility.decodeText(GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
    assertEquals("用户@例子", decodedText);
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:22,代码来源:SendReceiveWithInternationalAddressTest.java

示例7: messageHeaders

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void messageHeaders() throws Exception {
  greenMail.setUser("[email protected]", "bpmn");

  Session smtpSession = greenMail.getSmtp().createSession();

  MimeMessage message = new MimeMessage(smtpSession);
  message.setFrom(new InternetAddress("[email protected]"));
  message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
  message.addRecipient(Message.RecipientType.CC, new InternetAddress("[email protected]"));
  message.setSubject("subject");
  message.setText("body");

  GreenMailUtil.sendMimeMessage(message);

  PollMailResponse response = MailConnectors.pollMails()
      .createRequest()
        .folder("INBOX")
      .execute();

    List<Mail> mails = response.getMails();
    assertThat(mails).hasSize(1);

    Mail mail = mails.get(0);
    assertThat(mail.getFrom()).isEqualTo("[email protected]");
    assertThat(mail.getTo()).isEqualTo("[email protected]");
    assertThat(mail.getCc()).isEqualTo("[email protected]");
    assertThat(mail.getSubject()).isEqualTo("subject");
    assertThat(mail.getSentDate()).isNotNull();
    assertThat(mail.getReceivedDate()).isNotNull();
    assertThat(mail.getMessageNumber()).isEqualTo(1);
    assertThat(mail.getMessageId()).isNotNull();
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:34,代码来源:PollMailConnectorTest.java

示例8: messageWithSingleAttachmentOnly

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void messageWithSingleAttachmentOnly() throws Exception {
  greenMail.setUser("[email protected]", "bpmn");

  Session smtpSession = greenMail.getSmtp().createSession();
  MimeMessage message = MailTestUtil.createMimeMessage(smtpSession);

  message.setContent("text body", MailContentType.TEXT_PLAIN.getType());
  message.setFileName("attachment.txt");
  message.setDisposition(Part.ATTACHMENT);

  GreenMailUtil.sendMimeMessage(message);

  PollMailResponse response = MailConnectors.pollMails()
    .createRequest()
      .folder("INBOX")
    .execute();

  List<Mail> mails = response.getMails();
  assertThat(mails).hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getAttachments()).hasSize(1);

  Attachment mailAttachment = mail.getAttachments().get(0);
  assertThat(mailAttachment.getFileName()).isEqualTo("attachment.txt");
  assertThat(mailAttachment.getPath()).isNotNull();
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:29,代码来源:PollMailConnectorTest.java

示例9: messageWithAttachmentNoDownload

import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void messageWithAttachmentNoDownload() throws Exception {
  File attachment = new File(getClass().getResource("/attachment.txt").toURI());
  assertThat(attachment.exists()).isTrue();

  greenMail.setUser("[email protected]", "bpmn");

  Session session = greenMail.getSmtp().createSession();
  MimeMessage message = MailTestUtil.createMimeMessageWithAttachment(session, attachment);
  GreenMailUtil.sendMimeMessage(message);

  PollMailResponse response = MailConnectors.pollMails()
    .createRequest()
      .folder("INBOX")
      .downloadAttachments(false)
    .execute();

  List<Mail> mails = response.getMails();
  assertThat(mails).hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getAttachments()).hasSize(1);

  Attachment mailAttachment = mail.getAttachments().get(0);
  assertThat(mailAttachment.getFileName()).isEqualTo("attachment.txt");
  assertThat(mailAttachment.getPath()).isNull();
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:28,代码来源:PollMailConnectorTest.java

示例10: 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

示例11: 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.sendMimeMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。