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


Java MimeBodyPart类代码示例

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


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

示例1: getMessagePart

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
private static Multipart getMessagePart() throws MessagingException, IOException {
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(getVal("msg.Body"));
    multipart.addBodyPart(messageBodyPart);
    if (getBoolVal("attach.reports")) {
        LOG.info("Attaching Reports as zip");
        multipart.addBodyPart(getReportsBodyPart());
    } else {
        if (getBoolVal("attach.standaloneHtml")) {
            multipart.addBodyPart(getStandaloneHtmlBodyPart());
        }
        if (getBoolVal("attach.console")) {
            multipart.addBodyPart(getConsoleBodyPart());
        }
        if (getBoolVal("attach.screenshots")) {
            multipart.addBodyPart(getScreenShotsBodyPart());
        }
    }
    messageBodyPart.setContent(getVal("msg.Body")
            .concat("\n\n\n")
            .concat(MailComponent.getHTMLBody()), "text/html");
    return multipart;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:Mailer.java

示例2: setAttachment

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
public static void setAttachment(Message message, String filename) throws MessagingException {
    // Create a multipar message
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();

    //Set File
    DataSource source = new FileDataSource(filename);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);

    //Add "file part" to multipart
    multipart.addBodyPart(messageBodyPart);

    //Set multipart to message
    message.setContent(multipart);
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:17,代码来源:Solution.java

示例3: testSendMultipartEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
@Test
public void testSendMultipartEmail() throws Exception {
    mailService.sendEmail("[email protected]", "testSubject", "testContent", true, false);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    MimeMultipart mp = (MimeMultipart) message.getContent();
    MimeBodyPart part = (MimeBodyPart) ((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    part.writeTo(aos);
    assertThat(message.getSubject()).isEqualTo("testSubject");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getFrom()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getContent()).isInstanceOf(Multipart.class);
    assertThat(aos.toString()).isEqualTo("\r\ntestContent");
    assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:17,代码来源:MailServiceIntTest.java

示例4: testSendMultipartHtmlEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
@Test
public void testSendMultipartHtmlEmail() throws Exception {
    mailService.sendEmail("[email protected]", "testSubject", "testContent", true, true);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    MimeMultipart mp = (MimeMultipart) message.getContent();
    MimeBodyPart part = (MimeBodyPart) ((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    part.writeTo(aos);
    assertThat(message.getSubject()).isEqualTo("testSubject");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getFrom()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getContent()).isInstanceOf(Multipart.class);
    assertThat(aos.toString()).isEqualTo("\r\ntestContent");
    assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:17,代码来源:MailServiceIntTest.java

示例5: addAttachment

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
public static String addAttachment(MimeMultipart mm, String path)
{
	if(count == Integer.MAX_VALUE)
	{
		count = 0;
	}
	int cid = count++;
       try
	{
   		java.io.File file = new java.io.File(path);
   		MimeBodyPart mbp = new MimeBodyPart();
   		mbp.setDisposition(MimeBodyPart.INLINE);
   		mbp.setContent(new MimeMultipart("mixed"));
   		mbp.setHeader("Content-ID", "<" + cid + ">");
		mbp.setDataHandler(new DataHandler(new FileDataSource(file)));
        mbp.setFileName(new String(file.getName().getBytes("GBK"), "ISO-8859-1"));
        mm.addBodyPart(mbp);
        return String.valueOf(cid);
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
       return "";
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:26,代码来源:EmailUtil.java

示例6: buildMessage

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
private static Message buildMessage(Session session, String from, String recipients, String subject, String text, String filename) throws MessagingException, AddressException
{
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
    message.setSubject(subject);

    BodyPart messageTextPart = new MimeBodyPart();
    messageTextPart.setText(text);

    BodyPart messageAttachmentPart = new MimeBodyPart();
    DataSource source = new FileDataSource(new File(filename));
    messageAttachmentPart.setDataHandler(new DataHandler(source));
    messageAttachmentPart.setFileName(filename);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageTextPart);
    multipart.addBodyPart(messageAttachmentPart);
    message.setContent(multipart);

    return message;
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:23,代码来源:MailHelper.java

示例7: sendMultiPartEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
private void sendMultiPartEmail(String from, String to, String subject, String body) throws MessagingException {
    Properties props = createEmailProps(serverPort);
    Session session = Session.getInstance(props);

    Message msg = createBaseMessage(from, to, subject, session);

    MimeBodyPart p1 = new MimeBodyPart();
    p1.setText(body);

    MimeBodyPart p2 = new MimeBodyPart();
    p2.setText("Second part");

    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    mp.addBodyPart(p2);

    msg.setContent(mp);

    Transport.send(msg);
}
 
开发者ID:anlar,项目名称:LunaticSMTP,代码行数:21,代码来源:ServerTest.java

示例8: testSendMultipartEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
@Test
public void testSendMultipartEmail() throws Exception {
    mailService.sendEmail("[email protected]", "testSubject","testContent", true, false);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    MimeMultipart mp = (MimeMultipart) message.getContent();
    MimeBodyPart part = (MimeBodyPart)((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    part.writeTo(aos);
    assertThat(message.getSubject()).isEqualTo("testSubject");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getFrom()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getContent()).isInstanceOf(Multipart.class);
    assertThat(aos.toString()).isEqualTo("\r\ntestContent");
    assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:17,代码来源:MailServiceIntTest.java

示例9: testSendMultipartHtmlEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
@Test
public void testSendMultipartHtmlEmail() throws Exception {
    mailService.sendEmail("[email protected]", "testSubject","testContent", true, true);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    MimeMultipart mp = (MimeMultipart) message.getContent();
    MimeBodyPart part = (MimeBodyPart)((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    part.writeTo(aos);
    assertThat(message.getSubject()).isEqualTo("testSubject");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getFrom()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getContent()).isInstanceOf(Multipart.class);
    assertThat(aos.toString()).isEqualTo("\r\ntestContent");
    assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:17,代码来源:MailServiceIntTest.java

示例10: sendAttachMail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
public boolean sendAttachMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        Multipart multi = new MimeMultipart();
        BodyPart textBodyPart = new MimeBodyPart();
        textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
        multi.addBodyPart(textBodyPart);
        for (String path : mailInfo.getAttachFileNames()) {
            DataSource fds = new FileDataSource(path);
            BodyPart fileBodyPart = new MimeBodyPart();
            fileBodyPart.setDataHandler(new DataHandler(fds));
            fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
            multi.addBodyPart(fileBodyPart);
        }
        mailMessage.setContent(multi);
        mailMessage.saveChanges();
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:33,代码来源:SimpleMailSender.java

示例11: buildEmailMessage

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
private Message buildEmailMessage(EmailInfo emailInfo)
		throws AddressException, MessagingException, UnsupportedEncodingException {
	MimeMessage message = new MimeMessage(this.session);
	message.setFrom(new InternetAddress(emailInfo.getFrom(), "网页更新订阅系统", "UTF-8"));
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));

	Multipart multipart = new MimeMultipart();
	BodyPart messageBodyPart = new MimeBodyPart();
	messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
	multipart.addBodyPart(messageBodyPart);
	message.setContent(multipart);
	message.setSubject(emailInfo.getTitle());
	message.saveChanges();
	return message;
}
 
开发者ID:wrayzheng,项目名称:webpage-update-subscribe,代码行数:16,代码来源:EmailServer.java

示例12: addPart

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
/**
 * Add a part with the specified text to the specified position
 *
 * @param content the part's content
 * @param contentTypeSubtype the part's subtype of content type like plain (sub type of text/plain) or html (sub type of text/html)
 * @param charset the part's charset
 * @throws PackageException
 */
@PublicAtsApi
public void addPart(
                     String content,
                     String contentTypeSubtype,
                     String charset ) throws PackageException {

    // create a new inline part
    MimeBodyPart part = new MimeBodyPart();

    try {
        part.setText(content, charset, contentTypeSubtype);
        part.setDisposition(MimeBodyPart.INLINE);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }

    addPart(part, PART_POSITION_LAST);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:27,代码来源:MimePackage.java

示例13: addAttachment

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
/**
 * Add the specified file as an attachment
 *
 * @param fileName
 *            name of the file
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        FileDataSource ds = new FileDataSource(fileName);
        attPart.setDataHandler(new DataHandler(ds));
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(ds.getName());

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:MimePackage.java

示例14: testSendMultipartHtmlEmail

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
@Test
public void testSendMultipartHtmlEmail() throws Exception {
    mailService.sendEmail("[email protected]", "testSubject","testContent", true, true);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    MimeMultipart mp = (MimeMultipart) message.getContent();
    MimeBodyPart part = (MimeBodyPart)((MimeMultipart) mp.getBodyPart(0).getContent()).getBodyPart(0);
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    part.writeTo(aos);
    assertThat(message.getSubject()).isEqualTo("testSubject");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo("[email protected]mple.com");
    assertThat(message.getFrom()[0].toString()).isEqualTo("[email protected]");
    assertThat(message.getContent()).isInstanceOf(Multipart.class);
    assertThat(aos.toString()).isEqualTo("\r\ntestContent");
    assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:17,代码来源:MailServiceIntTest.java

示例15: setText

import javax.mail.internet.MimeBodyPart; //导入依赖的package包/类
/**
 * Set the given plain text and HTML text as alternatives, offering
 * both options to the email client. Requires multipart mode.
 * <p><b>NOTE:</b> Invoke {@link #addInline} <i>after</i> {@code setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param plainText the plain text for the message
 * @param htmlText the HTML text for the message
 * @throws MessagingException in case of errors
 */
public void setText(String plainText, String htmlText) throws MessagingException {
	Assert.notNull(plainText, "Plain text must not be null");
	Assert.notNull(htmlText, "HTML text must not be null");

	MimeMultipart messageBody = new MimeMultipart(MULTIPART_SUBTYPE_ALTERNATIVE);
	getMainPart().setContent(messageBody, CONTENT_TYPE_ALTERNATIVE);

	// Create the plain text part of the message.
	MimeBodyPart plainTextPart = new MimeBodyPart();
	setPlainTextToMimePart(plainTextPart, plainText);
	messageBody.addBodyPart(plainTextPart);

	// Create the HTML text part of the message.
	MimeBodyPart htmlTextPart = new MimeBodyPart();
	setHtmlTextToMimePart(htmlTextPart, htmlText);
	messageBody.addBodyPart(htmlTextPart);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:MimeMessageHelper.java


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