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


Java ByteArrayDataSource类代码示例

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


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

示例1: populateContentOnBodyPart

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
protected String populateContentOnBodyPart(BodyPart part, MailConfiguration configuration, Exchange exchange)
    throws MessagingException, IOException {

    String contentType = determineContentType(configuration, exchange);

    if (contentType != null) {
        LOG.trace("Using Content-Type {} for BodyPart: {}", contentType, part);

        // always store content in a byte array data store to avoid various content type and charset issues
        String data = exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange.getIn().getBody());
        // use empty data if the body was null for some reason (otherwise there is a NPE)
        data = data != null ? data : "";

        DataSource ds = new ByteArrayDataSource(data, contentType);
        part.setDataHandler(new DataHandler(ds));

        // set the content type header afterwards
        part.setHeader("Content-Type", contentType);
    }

    return contentType;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MailBinding.java

示例2: main

import javax.mail.util.ByteArrayDataSource; //导入依赖的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

示例3: readFrom

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Override
public SignedInput readFrom(Class<SignedInput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream entityStream) throws IOException, WebApplicationException {
    Class<?> baseType = null;
    Type baseGenericType = null;

    if (genericType instanceof ParameterizedType) {
        ParameterizedType param = (ParameterizedType) genericType;
        baseGenericType = param.getActualTypeArguments()[0];
        baseType = Types.getRawType(baseGenericType);
    }
    try {
        ByteArrayDataSource ds = new ByteArrayDataSource(entityStream, mediaType.toString());
        MimeMultipart mm = new MimeMultipart(ds);
        SignedInputImpl input = new SignedInputImpl();
        input.setType(baseType);
        input.setGenericType(baseGenericType);
        input.setAnnotations(annotations);
        input.setBody(mm);
        input.setProviders(providers);
        return input;
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:26,代码来源:SignedReader.java

示例4: createMimeMessageAttachments

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
/**
 * Creates a list of {@link MimeMessage} attachments using the given incoming e-mail.
 *
 * @param email The parsed e-mail.
 * @return A list containing the attachments, if any.
 * @throws Exception If there is an error while constructing the list of attachments.
 */
private List<BodyPart> createMimeMessageAttachments(Email email) throws Exception {

    List<BodyPart> attachments = new LinkedList<>();

    for (Attachment attachment : email.getAttachments()) {
        BodyPart attachmentBodyPart = new MimeBodyPart();
        attachmentBodyPart.setFileName(attachment.getAttachmentName());

        byte[] data = ByteStreams.toByteArray(attachment.getIs());
        DataSource source = new ByteArrayDataSource(data, "application/octet-stream");
        attachmentBodyPart.setDataHandler(new DataHandler(source));

        attachments.add(attachmentBodyPart);
    }

    return attachments;
}
 
开发者ID:stevesoltys,项目名称:carrier,代码行数:25,代码来源:SMTPMessageFactory.java

示例5: main

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
    clearConfigProperties();

    final Email emailNormal = new Email();
    emailNormal.setFromAddress("lollypop", "[email protected]");
    // don't forget to add your own address here ->
    emailNormal.addRecipient("C.Cane", YOUR_GMAIL_ADDRESS, RecipientType.TO);
    emailNormal.setText("We should meet up!");
    emailNormal.setTextHTML("<b>We should meet up!</b><img src='cid:thumbsup'>");
    emailNormal.setSubject("hey");

    // add two text files in different ways and a black thumbs up embedded image ->
    emailNormal.addAttachment("dresscode.txt", new ByteArrayDataSource("Black Tie Optional", "text/plain"));
    emailNormal.addAttachment("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==";
    emailNormal.addEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");

    // let's try producing and then consuming a MimeMessage ->
    final MimeMessage mimeMessage = Mailer.produceMimeMessage(emailNormal);
    final Email emailFromMimeMessage = new Email(mimeMessage);

    // note: the following statements will produce 6 new emails!
    sendMail(emailNormal);
    sendMail(emailFromMimeMessage); // should produce the exact same result as emailNormal!
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:26,代码来源:MailTestApp.java

示例6: sendBugReport

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
public void sendBugReport(BugReport report) throws MailException, MessagingException {
    MimeMessage message = this.mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setTo(bugReportEmail);
    helper.setFrom(from);
    helper.setSubject(report.getSubject());
    helper.setText(report.getDescription());
    if (report.getAttachments() != null) {
        for (BugReportAttachment attachment : report.getAttachments()) {
            // Decode base64 encoded data
            byte[] data =  Base64.getDecoder().decode(attachment.getData());
            ByteArrayDataSource dataSource = new ByteArrayDataSource(data, attachment.getMimetype());
            helper.addAttachment(attachment.getName(), dataSource);
        }
    }
    this.mailSender.send(message);
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:18,代码来源:EmailUtil.java

示例7: testConsumer

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Test
public void testConsumer() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }

    context.createProducerTemplate().send("cxf:bean:consumerEndpoint", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            assertEquals("Get a wrong Content-Type header", "application/xop+xml", exchange.getIn().getHeader("Content-Type"));
            List<Source> elements = new ArrayList<Source>();
            elements.add(new DOMSource(StaxUtils.read(new StringReader(getRequestMessage())).getDocumentElement()));
            CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
                elements, null);
            exchange.getIn().setBody(body);
            exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, 
                new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));

            exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, 
                new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CxfMtomConsumerPayloadModeTest.java

示例8: process

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
    CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);
    
    // verify request
    Assert.assertEquals(1, in.getBody().size());
    
    DataHandler dr = exchange.getIn().getAttachment(MtomTestHelper.REQ_PHOTO_CID);
    Assert.assertEquals("application/octet-stream", dr.getContentType());
    MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
       
    dr = exchange.getIn().getAttachment(MtomTestHelper.REQ_IMAGE_CID);
    Assert.assertEquals("image/jpeg", dr.getContentType());
    MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));

    // create response
    List<Source> elements = new ArrayList<Source>();
    elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.MTOM_DISABLED_RESP_MESSAGE)).getDocumentElement()));
    CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
        elements, null);
    exchange.getOut().setBody(body);
    exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID, 
        new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));

    exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID, 
        new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:CxfMtomDisabledConsumerPayloadModeTest.java

示例9: populateContentOnMimeMessage

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
protected String populateContentOnMimeMessage(MimeMessage part, MailConfiguration configuration, Exchange exchange)
    throws MessagingException, IOException {

    String contentType = determineContentType(configuration, exchange);

    LOG.trace("Using Content-Type {} for MimeMessage: {}", contentType, part);

    String body = exchange.getIn().getBody(String.class);
    if (body == null) {
        body = "";
    }

    // always store content in a byte array data store to avoid various content type and charset issues
    DataSource ds = new ByteArrayDataSource(body, contentType);
    part.setDataHandler(new DataHandler(ds));

    // set the content type header afterwards
    part.setHeader("Content-Type", contentType);

    return contentType;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MailBinding.java

示例10: roundtripWithBinaryAttachments

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Test
public void roundtripWithBinaryAttachments() throws IOException {
    String attContentType = "application/binary";
    byte[] attText = {0, 1, 2, 3, 4, 5, 6, 7};
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    DataSource ds = new ByteArrayDataSource(attText, attContentType);
    in.addAttachment(attFileName, new DataHandler(ds));
    Exchange result = template.send("direct:roundtrip", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertArrayEquals(attText, os.toByteArray());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MimeMultipartDataFormatTest.java

示例11: roundtripWithBinaryAttachmentsAndBinaryContent

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Test
public void roundtripWithBinaryAttachmentsAndBinaryContent() throws IOException {
    String attContentType = "application/binary";
    byte[] attText = {0, 1, 2, 3, 4, 5, 6, 7};
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    DataSource ds = new ByteArrayDataSource(attText, attContentType);
    in.addAttachment(attFileName, new DataHandler(ds));
    Exchange result = template.send("direct:roundtripbinarycontent", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertArrayEquals(attText, os.toByteArray());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MimeMultipartDataFormatTest.java

示例12: addOneDocument

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
protected OMElement addOneDocument(OMElement request, String document, String documentId) throws IOException {
	OMFactory fac = OMAbstractFactory.getOMFactory();
	OMNamespace ns = fac.createOMNamespace("urn:ihe:iti:xds-b:2007" , null);
	OMElement docElem = fac.createOMElement("Document", ns);
	docElem.addAttribute("id", documentId, null);

       // A string, turn it into an StreamSource
    DataSource ds = new ByteArrayDataSource(document, "text/xml"); 
	DataHandler handler = new DataHandler(ds);
	 
       OMText binaryData = fac.createOMText(handler, true);
       docElem.addChild(binaryData);

       Iterator iter = request.getChildrenWithLocalName("SubmitObjectsRequest");
       OMElement submitObjectsRequest = null;
       for (;iter.hasNext();) {
       	submitObjectsRequest = (OMElement)iter.next();
       	if (submitObjectsRequest != null)
       		break;
       }
       submitObjectsRequest.insertSiblingAfter(docElem);
       return request;
}
 
开发者ID:jembi,项目名称:openxds,代码行数:24,代码来源:XdsTest.java

示例13: testBuilderSimpleBuildWithStandardEmail

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Test
public void testBuilderSimpleBuildWithStandardEmail()
		throws IOException {
	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==";
	
	final Email email = EmailBuilder.startingBlank()
			.from("lollypop", "[email protected]")
			.to("C.Cane", "[email protected]")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
			.withSubject("hey")
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png")
			.buildEmail();
	
	assertThat(EmailHelper.createDummyEmailBuilder(true, true, false).buildEmail()).isEqualTo(email);
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:21,代码来源:EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest.java

示例14: testBuilderSimpleBuildWithStandardEmail_PlusOptionals

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
@Test
public void testBuilderSimpleBuildWithStandardEmail_PlusOptionals()
		throws IOException {
	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==";
	
	final Email email = EmailBuilder.startingBlank()
			.from("lollypop", "[email protected]")
			.withReplyTo("lollypop-reply", "[email protected]")
			.withBounceTo("lollypop-bounce", "[email protected]")
			.to("C.Cane", "[email protected]")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
			.withSubject("hey")
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png")
			.withDispositionNotificationTo("[email protected]")
			.withReturnReceiptTo("Complex Email", "[email protected]")
			.withHeader("dummyHeader", "dummyHeaderValue")
			.buildEmail();
	
	assertThat(EmailHelper.createDummyEmailBuilder(true, false, true).buildEmail()).isEqualTo(email);
}
 
开发者ID:bbottema,项目名称:simple-java-mail,代码行数:26,代码来源:EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest.java

示例15: appendIcsBody

import javax.mail.util.ByteArrayDataSource; //导入依赖的package包/类
protected MimeMessage appendIcsBody(MimeMessage msg, MailMessage m) throws Exception {
	log.debug("setMessageBody for iCal message");
	// -- Create a new message --
	Multipart multipart = new MimeMultipart();

	Multipart multiBody = new MimeMultipart("alternative");
	BodyPart html = new MimeBodyPart();
	html.setDataHandler(new DataHandler(new ByteArrayDataSource(m.getBody(), "text/html; charset=UTF-8")));
	multiBody.addBodyPart(html);

	BodyPart iCalContent = new MimeBodyPart();
	iCalContent.addHeader("content-class", "urn:content-classes:calendarmessage");
	iCalContent.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"text/calendar; charset=UTF-8; method=REQUEST")));
	multiBody.addBodyPart(iCalContent);
	BodyPart body = new MimeBodyPart();
	body.setContent(multiBody);
	multipart.addBodyPart(body);

	BodyPart iCalAttachment = new MimeBodyPart();
	iCalAttachment.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(m.getIcs()),
			"application/ics")));
	iCalAttachment.removeHeader("Content-Transfer-Encoding");
	iCalAttachment.addHeader("Content-Transfer-Encoding", "base64");
	iCalAttachment.removeHeader("Content-Type");
	iCalAttachment.addHeader("Content-Type", "application/ics");
	iCalAttachment.setFileName("invite.ics");
	multipart.addBodyPart(iCalAttachment);

	msg.setContent(multipart);
	return msg;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:33,代码来源:MailHandler.java


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