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


Java GreenMailUtil类代码示例

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


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

示例1: createTestMessages

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
public void createTestMessages() {
    try {
        GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");

        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        user.deliver(createMimeMessage("[email protected]", subject, body, null));
        user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
        user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
        user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
        user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
        user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom", 
                 Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));

        Session imapSession = greenMail.getImap().createSession();
        Store store = imapSession.getStore("imap");
        store.connect(TEST_RECIP, "password");
        
        Folder defaultFolder = store.getDefaultFolder();  
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        
        Folder ads = defaultFolder.getFolder("Ads");
        ads.create(Folder.HOLDS_MESSAGES);   
        
        Folder spam = defaultFolder.getFolder("Spam");
        spam.create(Folder.HOLDS_MESSAGES); 
    } catch (MessagingException ex) {
        Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:32,代码来源:TestMailUtil.java

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

示例3: testAllServices

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
public void testAllServices() throws MessagingException {
    // Send messages via SMTP and secure SMTPS
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test1", "Test GreenMail Docker service",
            ServerSetupTest.SMTP.createCopy(bindAddress));
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test2", "Test GreenMail Docker service",
            ServerSetupTest.SMTPS.createCopy(bindAddress));

    // IMAP
    for (ServerSetup setup : Arrays.asList(
            ServerSetupTest.IMAP.createCopy(bindAddress),
            ServerSetupTest.IMAPS.createCopy(bindAddress),
            ServerSetupTest.POP3.createCopy(bindAddress),
            ServerSetupTest.POP3S.createCopy(bindAddress))) {
        final Store store = Session.getInstance(setup.configureJavaMailSessionProperties(null, false)).getStore();
        store.connect("[email protected]", "[email protected]");
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            assertEquals("Can not check mails using "+store.getURLName(), 2, folder.getMessageCount());
        } finally {
            store.close();
        }
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:28,代码来源:DockerServiceIT.java

示例4: testSendEmailActivation

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
public void testSendEmailActivation() {
	UserEntity user = new UserEntity()
		.setId(UUID.randomUUID().toString())
		.setUsername("user")
		.setPassword(passwordEncoder.encode("user"))
		.setEmail("[email protected]");
	tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user);
	tokenStoreService.sendTokenNotification(TokenStoreType.CHANGE_PASSWORD, user);

	assertThat(greenMail.waitForIncomingEmail(1000, 2)).isTrue();
	MimeMessage messageActivation = greenMail.getReceivedMessages()[0];
	assertThat(GreenMailUtil.getBody(messageActivation)).contains("activate?at=");
	MimeMessage messageChangePassword = greenMail.getReceivedMessages()[1];
	assertThat(GreenMailUtil.getBody(messageChangePassword)).contains("update?rt=");

	user.setEmail("@codenergic.org");
	assertThatThrownBy(() -> tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user))
		.isInstanceOf(RegistrationException.class);
	assertThatThrownBy(() -> tokenStoreService.sendTokenNotification(TokenStoreType.CHANGE_PASSWORD, user))
		.isInstanceOf(RegistrationException.class);
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:23,代码来源:TokenStoreServiceTest.java

示例5: readDotTerminatedContent

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
/**
 * Reads the contents of the stream until
 * <CRLF>.<CRLF> is encountered.
 * <p/>
 * <p/>
 * It would be possible and prehaps desirable to prevent the
 * adding of an unnecessary CRLF at the end of the message, but
 * it hardly seems worth 30 seconds of effort.
 * </p>
 */
public void readDotTerminatedContent(BufferedReader in)
        throws IOException {
    _content = _workspace.getTmpFile();
    Writer data = _content.getWriter();
    PrintWriter dataWriter = new InternetPrintWriter(data);

    while (true) {
        String line = in.readLine();
        if (line == null)
            throw new EOFException("Did not receive <CRLF>.<CRLF>");

        if (".".equals(line)) {
            dataWriter.close();

            break;
        } else {
            dataWriter.println(line);
        }
    }
    try {
        message = GreenMailUtil.newMimeMessage(_content.getAsString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:36,代码来源:MovingMessage.java

示例6: execute

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
public void execute(Pop3Connection conn, Pop3State state,
                    String cmd) {
    try {
        MailFolder inbox = state.getFolder();
        String[] cmdLine = cmd.split(" ");

        String msgNumStr = cmdLine[1];
        List msgList = inbox.getMessages(new MsgRangeFilter(msgNumStr, false));
        if (msgList.size() != 1) {
            conn.println("-ERR no such message");

            return;
        }

        SimpleStoredMessage msg = (SimpleStoredMessage) msgList.get(0);
        String email = GreenMailUtil.getWholeMessage(msg.getMimeMessage());
        conn.println("+OK");
        conn.print(new StringReader(email));
        conn.println();
        conn.println(".");
        msg.getFlags().add(Flags.Flag.SEEN);
    } catch (Exception e) {
        conn.println("-ERR " + e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:26,代码来源:RetrCommand.java

示例7: shouldSendEmail

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
public void shouldSendEmail() throws Exception {
    // Given
    String to = "[email protected]";
    String from = "[email protected]";
    String title = "Title";
    String content = "Content";
    // When
    emailSender.sendEmail(to, from, title, content);
    // Then
    MimeMessage[] receivedMessages = server.getReceivedMessages();
    assertThat(receivedMessages.length).isEqualTo(1);

    MimeMessage receivedMessage = receivedMessages[0];
    assertThat(receivedMessage.getAllRecipients()[0].toString()).isEqualTo(to); //to
    assertThat(receivedMessage.getFrom()[0].toString()).isEqualTo(from); //from
    assertThat(receivedMessage.getSubject()).isEqualTo(title); //title
    assertThat(receivedMessage.getContent().toString()).contains(content); //content
    //Or
    assertThat(content).isEqualTo(GreenMailUtil.getBody(server.getReceivedMessages()[0]));
}
 
开发者ID:kchrusciel,项目名称:Spring-Boot-Examples,代码行数:22,代码来源:EmailSenderTest.java

示例8: register

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
public void register() throws Exception {
    mockMvc.perform(
            post(URL_REGISTRATION)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(asJsonString(new RequestUserDTO(USERNAME, EMAIL_TO, ""))))
            .andExpect(status().isOk());

    MimeMessage[] receivedMessages = testSmtp.getReceivedMessages();
    assertEquals(1, receivedMessages.length);
    MimeMessage message = receivedMessages[0];
    assertEquals(EmailSenderImpl.SUBJECT, message.getSubject());
    String body = GreenMailUtil.getBody(message).replaceAll("=\r?\n", "");
    Address to = message.getAllRecipients()[0];
    Address from = message.getFrom()[0];
    assertEquals(EMAIL_TO, to.toString());
    assertEquals(EmailSenderImpl.EMAIL_FROM, from.toString());
    String url = TestUtils.extractLink(body);
    mockMvc.perform(get(url))
            .andExpect(status().isOk());

}
 
开发者ID:egch,项目名称:sushi-bar-BE,代码行数:23,代码来源:RegistrationControllerTest.java

示例9: testDoPrivateExam

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
@RunAsStudent
public void testDoPrivateExam() throws Exception {
    Exam studentExam = createPrivateStudentExam();
    Result result = request(Helpers.PUT, String.format("/app/student/exam/%s", studentExam.getHash()), null);
    assertThat(result.status()).isEqualTo(200);

    // Check that correct mail was sent
    assertThat(greenMail.waitForIncomingEmail(MAIL_TIMEOUT, 1)).isTrue();
    MimeMessage[] mails = greenMail.getReceivedMessages();
    assertThat(mails).hasSize(1);
    assertThat(mails[0].getFrom()[0].toString()).contains(ConfigFactory.load().getString("sitnet.email.system.account"));
    assertThat(mails[0].getSubject()).isEqualTo("Personal exam has been returned");
    String body = GreenMailUtil.getBody(mails[0]);
    String reviewLink = String.format("%s/assessments/%d",
            ConfigFactory.load().getString("sitnet.application.hostname"), studentExam.getId());
    String reviewLinkElement = String.format("<a href=\"%s\">%s</a>", reviewLink, "Link to evaluation");
    assertThat(body).contains(reviewLinkElement);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:StudentExamControllerTest.java

示例10: testAbortPrivateExam

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
@RunAsStudent
public void testAbortPrivateExam() throws Exception {
    Exam studentExam = createPrivateStudentExam();
    Result result = request(Helpers.PUT, String.format("/app/student/exam/abort/%s", studentExam.getHash()), null);
    assertThat(result.status()).isEqualTo(200);

    // Check that correct mail was sent
    assertThat(greenMail.waitForIncomingEmail(MAIL_TIMEOUT, 1)).isTrue();
    MimeMessage[] mails = greenMail.getReceivedMessages();
    assertThat(mails).hasSize(1);
    assertThat(mails[0].getFrom()[0].toString()).contains(ConfigFactory.load().getString("sitnet.email.system.account"));
    assertThat(mails[0].getSubject()).isEqualTo("Personal exam has been abandoned");
    String body = GreenMailUtil.getBody(mails[0]);
    // Make sure there is no link to review
    assertThat(body).doesNotContain("<a href");
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:StudentExamControllerTest.java

示例11: pollMailWithTextBody

import com.icegreen.greenmail.util.GreenMailUtil; //导入依赖的package包/类
@Test
@Deployment(resources = "processes/mail-poll.bpmn")
public void pollMailWithTextBody() throws MessagingException {
  greenMail.setUser("[email protected]", "bpmn");

  GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "subject", "text body");

  ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("poll-mails");

  @SuppressWarnings("unchecked")
  List<Mail> mails = (List<Mail>) engineRule.getRuntimeService().getVariable(processInstance.getId(), "mails");

  assertThat(mails)
    .isNotNull()
    .hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getFrom()).isEqualTo("[email protected]");
  assertThat(mail.getSubject()).isEqualTo("subject");
  assertThat(mail.getText()).isEqualTo("text body");
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:22,代码来源:PollMailConnectorProcessTest.java

示例12: pollSingleMail

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

  GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "subject", "text body");

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

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

  Mail mail = mails.get(0);
  assertThat(mail.getSubject()).isEqualTo("subject");
  assertThat(mail.getText()).isEqualTo("text body");
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:19,代码来源:PollMailConnectorTest.java

示例13: pollMultipleMails

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

  GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "mail-1", "body");
  GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "mail-2", "body");

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

  List<Mail> mails = response.getMails();
  assertThat(mails)
    .hasSize(2)
    .extracting("subject")
    .contains("mail-1", "mail-2");
}
 
开发者ID:camunda,项目名称:camunda-bpm-mail,代码行数:19,代码来源:PollMailConnectorTest.java

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

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


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