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


Java EmailBuilder类代码示例

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


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

示例1: main

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
public static void main(final String[] args)
		throws Exception {
	final EmailPopulatingBuilder emailPopulatingBuilderNormal = EmailBuilder.startingBlank();
	emailPopulatingBuilderNormal.from("lollypop", "[email protected]");
	// don't forget to add your own address here ->
	emailPopulatingBuilderNormal.to("C.Cane", YOUR_GMAIL_ADDRESS);
	emailPopulatingBuilderNormal.withPlainText("We should meet up!");
	emailPopulatingBuilderNormal.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>");
	emailPopulatingBuilderNormal.withSubject("hey");
	
	// add two text files in different ways and a black thumbs up embedded image ->
	emailPopulatingBuilderNormal.withAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain"));
	emailPopulatingBuilderNormal.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain");
	String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
	emailPopulatingBuilderNormal.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");
	
	// let's try producing and then consuming a MimeMessage ->
	Email emailNormal = emailPopulatingBuilderNormal.buildEmail();
	final MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailNormal);
	final Email emailFromMimeMessage = EmailConverter.mimeMessageToEmail(mimeMessage);
	
	// note: the following statements will produce 6 new emails!
	sendMail(emailNormal);
	sendMail(emailFromMimeMessage); // should produce the exact same result as emailPopulatingBuilderNormal!
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:26,代码来源:MailTestDemoApp.java

示例2: executeMailTask

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
private void executeMailTask(MailTask mailTask) {

        log.info("------------------------execute queue task------------------------");
        log.info("Send mail task consumed on thread: T{}", Thread.currentThread().getId());

        log.info(mailTask.getTitle());

        try {

            Email email = new EmailBuilder()
                .from(mailTask.getSenderName(), mailTask.getFrom())
                .to(mailTask.getReceiverName(), mailTask.getTo())
                .subject(mailTask.getTitle())
                .text(mailTask.getContent())
                .build();
            mailer.sendMail(email);
        } catch (Exception e) {

            log.error("send mail error", e);
            e.printStackTrace();
        }
    }
 
开发者ID:thundernet8,项目名称:Elune,代码行数:23,代码来源:MailMQServiceImpl.java

示例3: createMailSession_ReplyToMessage_NotAll_AndCustomReferences

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
@Test
public void createMailSession_ReplyToMessage_NotAll_AndCustomReferences()
		throws IOException, MessagingException {
	// send initial mail
	mailer.sendMail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg").buildEmail());
	MimeMessage receivedMimeMessage = smtpServerRule.getOnlyMessage();
	EmailPopulatingBuilder receivedEmailPopulatingBuilder = mimeMessageToEmailBuilder(receivedMimeMessage);
	
	// send reply to initial mail
	Email reply = EmailBuilder
			.replyingTo(assertSendingEmail(receivedEmailPopulatingBuilder))
			.withHeader("References", "dummy-references")
			.from("[email protected]")
			.withPlainText("This is the reply")
			.buildEmail();
	
	// test received reply to initial mail
	mailer.sendMail(reply);
	MimeMessage receivedMimeMessageReply1 = smtpServerRule.getOnlyMessage("[email protected]");
	Email receivedReply = mimeMessageToEmail(receivedMimeMessageReply1);
	
	EmailAssert.assertThat(receivedReply).hasSubject("Re: hey");
	EmailAssert.assertThat(receivedReply).hasOnlyRecipients(new Recipient("lollypop-replyto", "[email protected]", TO));
	assertThat(receivedReply.getHeaders()).contains(entry("In-Reply-To", receivedEmailPopulatingBuilder.getId()));
	assertThat(receivedReply.getHeaders()).contains(entry("References", "dummy-references"));
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:27,代码来源:MailerLiveTest.java

示例4: writeReport

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Render the report HTML using Jtwig and send the result to the recipient emails.
 */
@Override
public void writeReport(List<TestSuite> testSuites) throws IOException {
    if (testSuites == null) {
        testSuites = Collections.emptyList();
    }
    log.info("Sending report email for {} test suites", testSuites.size());
    List<TestSuiteModel> testList = new ArrayList<>(testSuites.size());
    boolean hasError = false;
    for (TestSuite testSuite : testSuites) {
        TestSuiteModel testSuiteModel = new TestSuiteModel(testSuite);
        hasError = hasError || !testSuiteModel.allPassed();
        testList.add(testSuiteModel);
    }
    JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/email.twig");
    JtwigModel model = JtwigModel.newModel()
                                 .with("error", hasError)
                                 .with("testList", testList);
    String reportHtml = template.render(model);
    EmailBuilder emailBuilder = new EmailBuilder().from(senderName, fromEmail)
                                                  .replyTo(senderName, replyTo)
                                                  .subject("Validatar Report – " + (hasError ? "Test Errors" : "Tests Passed"))
                                                  .addHeader("X-Priority", 2)
                                                  .textHTML(reportHtml);
    for (String recipientEmail : recipientEmails) {
        emailBuilder.to(recipientEmail);
    }
    Email reportEmail = emailBuilder.build();
    ServerConfig mailServerConfig = new ServerConfig(smtpHost, smtpPort);
    Mailer reportMailer = new Mailer(mailServerConfig, TransportStrategy.SMTP_TLS);
    sendEmail(reportMailer, reportEmail);
    log.info("Finished sending report to recipients");
}
 
开发者ID:yahoo,项目名称:validatar,代码行数:38,代码来源:EmailFormatter.java

示例5: mimeMessageToEmailBuilder

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
/**
 * @param mimeMessage The MimeMessage from which to create the {@link Email}.
 */
public static EmailPopulatingBuilder mimeMessageToEmailBuilder(@Nonnull final MimeMessage mimeMessage) {
	checkNonEmptyArgument(mimeMessage, "mimeMessage");
	final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
	buildEmailFromMimeMessage(emailPopulatingBuilder, MimeMessageParser.parseMimeMessage(mimeMessage));
	return emailPopulatingBuilder;
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:10,代码来源:EmailConverter.java

示例6: outlookMsgToEmail

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
/**
 * @param msgData The content of an Outlook (.msg) message from which to create the {@link Email}.
 */
public static Email outlookMsgToEmail(@Nonnull final String msgData) {
	final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
	final OutlookMessage outlookMessage = OutlookMessageParser.parseOutlookMsg(checkNonEmptyArgument(msgData, "msgData"));
	buildEmailFromOutlookMessage(emailPopulatingBuilder, outlookMessage);
	return emailPopulatingBuilder.buildEmail();
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:10,代码来源:EmailConverter.java

示例7: outlookMsgToEmailBuilder

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
/**
 * @param msgInputStream The content of an Outlook (.msg) message from which to create the {@link Email}.
 */
public static EmailPopulatingBuilder outlookMsgToEmailBuilder(@Nonnull final InputStream msgInputStream) {
	final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.ignoringDefaults().startingBlank();
	final OutlookMessage outlookMessage = OutlookMessageParser.parseOutlookMsg(checkNonEmptyArgument(msgInputStream, "msgInputStream"));
	buildEmailFromOutlookMessage(emailPopulatingBuilder, outlookMessage);
	return emailPopulatingBuilder;
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:10,代码来源:EmailConverter.java

示例8: createMailSession_ReplyToMessage

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
@Test
public void createMailSession_ReplyToMessage()
		throws IOException, MessagingException {
	// send initial mail
	mailer.sendMail(readOutlookMessage("test-messages/HTML mail with replyto and attachment and embedded image.msg").buildEmail());
	MimeMessage receivedMimeMessage = smtpServerRule.getOnlyMessage();
	EmailPopulatingBuilder receivedEmailPopulatingBuilder = mimeMessageToEmailBuilder(receivedMimeMessage);
	
	// send reply to initial mail
	Email reply = EmailBuilder
			.replyingToAll(assertSendingEmail(receivedEmailPopulatingBuilder))
			.from("[email protected]")
			.withPlainText("This is the reply")
			.buildEmail();
	
	// test received reply to initial mail
	mailer.sendMail(reply);
	MimeMessage receivedMimeMessageReply1 = smtpServerRule.getMessage("[email protected]");
	MimeMessage receivedMimeMessageReply2 = smtpServerRule.getMessage("[email protected]");
	Email receivedReply1 = mimeMessageToEmail(receivedMimeMessageReply1);
	Email receivedReply2 = mimeMessageToEmail(receivedMimeMessageReply2);
	
	assertThat(receivedReply1).isEqualTo(receivedReply2);
	EmailAssert.assertThat(receivedReply1).hasSubject("Re: hey");
	EmailAssert.assertThat(receivedReply1).hasOnlyRecipients(
			new Recipient("lollypop-replyto", "[email protected]", TO),
			new Recipient("Bottema, Benny", "[email protected]", TO)
	);
	assertThat(receivedReply1.getHeaders()).contains(entry("In-Reply-To", receivedEmailPopulatingBuilder.getId()));
	assertThat(receivedReply1.getHeaders()).contains(entry("References", receivedEmailPopulatingBuilder.getId()));
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:32,代码来源:MailerLiveTest.java

示例9: createDummyEmailBuilder

import org.simplejavamail.email.EmailBuilder; //导入依赖的package包/类
public static EmailPopulatingBuilder createDummyEmailBuilder(@Nullable String id, boolean includeSubjectAndBody, boolean basicFields, boolean includeCustomHeaders)
		throws IOException {
	EmailPopulatingBuilder builder = EmailBuilder.startingBlank()
			.fixingMessageId(id)
			.from("lollypop", "[email protected]")
			// don't forget to add your own address here ->
			.to("C.Cane", "[email protected]shop.org");
	
	if (!basicFields) {
		// normally not needed, but for the test it is because the MimeMessage will
		// have it added automatically as well, so the parsed Email will also have it then
		builder = builder
			.withReplyTo("lollypop-reply", "[email protected]")
			.withBounceTo("lollypop-bounce", "[email protected]");
	}
	if (includeSubjectAndBody) {
		builder = builder
			.withSubject("hey")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>");
	}

	if (includeCustomHeaders) {
		builder = builder
			.withHeader("dummyHeader", "dummyHeaderValue")
			.withDispositionNotificationTo("[email protected]")
			.withReturnReceiptTo("Complex Email", "[email protected]");
	}

	// add two text files in different ways and a black thumbs up embedded image ->
	ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
	namedAttachment.setName("dresscode.txt"); // normally not needed, but otherwise the equals will fail
	String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
	
	return builder
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:40,代码来源:EmailHelper.java


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