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


Java MimeMessage.getContent方法代码示例

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


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

示例1: testSendMultipartEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的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

示例2: testSendMultipartHtmlEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的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

示例3: testSendMultipartEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的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

示例4: testSendMultipartHtmlEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的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

示例5: convert

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public Email convert(RawData rawData) throws IOException {
    try {
        Session s = Session.getDefaultInstance(new Properties());
        MimeMessage mimeMessage = new MimeMessage(s, rawData.getContentAsStream());
        String subject = Objects.toString(mimeMessage.getSubject(), UNDEFINED);
        ContentType contentType = ContentType.fromString(mimeMessage.getContentType());
        Object messageContent = mimeMessage.getContent();

        switch (contentType) {
            case HTML:
            case PLAIN:
                return buildPlainOrHtmlEmail(rawData, subject, contentType, messageContent);
            case MULTIPART_ALTERNATIVE:
                return buildMultipartAlternativeMail(rawData, subject, (Multipart) messageContent);
            default:
                throw new IllegalStateException("Unsupported e-mail content type " + contentType.name());
        }
    } catch (MessagingException e) {
        return buildFallbackEmail(rawData);
    }
}
 
开发者ID:gessnerfl,项目名称:fake-smtp-server,代码行数:22,代码来源:EmailFactory.java

示例6: processMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void processMessage()
{
	System.out.println("Process message");
	try
	{
		Session session = Session.getDefaultInstance(new Properties());
		InputStream inputStream = new ByteArrayInputStream(message.getBytes());
		MimeMessage mimeMessage = new MimeMessage(session,inputStream);
		if(mimeMessage.isMimeType(InboxVariables.plainMime))
		{
			plainMessage = mimeMessage.getContent().toString();
		}
		else if(mimeMessage.isMimeType(InboxVariables.multipartMime))
		{
			MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent();
			processMimeMultipart(mimeMultipart);
		}
		subject = mimeMessage.getSubject();
		System.out.println("Message processed");
	}
	catch(Exception ex)
	{
		ex.printStackTrace(System.err);
	}
}
 
开发者ID:travispessetto,项目名称:OrigamiSMTP,代码行数:26,代码来源:Message.java

示例7: transformInternal

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception
{
    InputStream contentInputStream = null;
    try{
        contentInputStream = reader.getContentInputStream();
        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), contentInputStream);

        final StringBuilder sb = new StringBuilder();
        Object content = mimeMessage.getContent();
        if (content instanceof Multipart)
        {
            processMultiPart((Multipart) content,sb);
        }
        else
        {
            sb.append(content.toString());
        }
        writer.putContent(sb.toString());
    }
    finally
    {
        if (contentInputStream != null)
        {
            try
            {
            contentInputStream.close();
            }
            catch ( IOException e)
            {
                //stop exception propagation
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:EMLTransformer.java

示例8: testUnmodifiedMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void testUnmodifiedMessage() throws Exception
{
    // Get test message UID
    final Long uid = getMessageUid(folder, 1);
    // Get Message size
    final int count = getMessageSize(folder, uid);

    // Make multiple message reading
    for (int i = 0; i < 100; i++)
    {
        // Get random offset
        int n = (int) ((int) 100 * Math.random());

        // Get first part
        BODY body = getMessageBodyPart(folder, uid, 0, count - n);
        // Read second message part
        BODY bodyRest = getMessageBodyPart(folder, uid, count - n, n);

        // Creating and parsing message from 2 parts
        MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()),
                new BufferedInputStream(bodyRest.getByteArrayInputStream())));

        MimeMultipart content = (MimeMultipart) message.getContent();
        // Reading first part - should be successful
        assertNotNull(content.getBodyPart(0).getContent());
        // Reading second part - should be successful
        assertNotNull(content.getBodyPart(1).getContent());
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:ImapMessageTest.java

示例9: extractAttachments

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void extractAttachments(NodeRef messageRef, MimeMessage originalMessage) throws IOException, MessagingException
{
    NodeRef attachmentsFolderRef = null;
    String attachmentsFolderName = null;
    boolean createFolder = false;
    switch (attachmentsExtractorMode)
    {
    case SAME:
        attachmentsFolderRef = nodeService.getPrimaryParent(messageRef).getParentRef();
        break;
    case COMMON:
        attachmentsFolderRef = this.attachmentsFolderRef;
        break;
    case SEPARATE:
    default:
        String messageName = (String) nodeService.getProperty(messageRef, ContentModel.PROP_NAME);
        attachmentsFolderName = messageName + "-attachments";
        createFolder = true;
        break;
    }
    if (!createFolder)
    {
        nodeService.createAssociation(messageRef, attachmentsFolderRef, ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
    }
 
    Object content = originalMessage.getContent();
    if (content instanceof Multipart)
    {
        Multipart multipart = (Multipart) content;
 
        for (int i = 0, n = multipart.getCount(); i < n; i++)
        {
            Part part = multipart.getBodyPart(i);
            if ("attachment".equalsIgnoreCase(part.getDisposition()))
            {
                if (createFolder)
                {
                    attachmentsFolderRef = createAttachmentFolder(messageRef, attachmentsFolderName);
                    createFolder = false;
                }
                createAttachment(messageRef, attachmentsFolderRef, part);
            }
        }
    }
 
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:47,代码来源:AttachmentsExtractor.java

示例10: testMessageRenamedBetweenReads

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void testMessageRenamedBetweenReads() throws Exception
{
    // Get test message UID
    final Long uid = getMessageUid(folder, 1);
    // Get Message size
    final int count = getMessageSize(folder, uid);

    // Get first part
    // Split the message into 2 part using a non multiple of 4 - 103 is a prime number
    // as the BASE64Decoder may not throw the IOException
    // see MNT-12995
    BODY body = getMessageBodyPart(folder, uid, 0, count - 103);

    // Rename message. The size of letter describing the node will change
    // These changes should be committed because it should be visible from client
    NodeRef contentNode = findNode(companyHomePathInStore + TEST_FILE);
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    fileFolderService.rename(contentNode, "testtesttesttesttesttesttesttesttesttest");
    txn.commit();

    // Read second message part
    BODY bodyRest = getMessageBodyPart(folder, uid, count - 103, 103);

    // Creating and parsing message from 2 parts
    MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()),
            new BufferedInputStream(bodyRest.getByteArrayInputStream())));

    // Reading first part - should be successful
    MimeMultipart content = (MimeMultipart) message.getContent();
    assertNotNull(content.getBodyPart(0).getContent());

    try
    {
        // Reading second part cause error
        content.getBodyPart(1).getContent();
        fail("Should raise an IOException");
    }
    catch (IOException e)
    {
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:43,代码来源:ImapMessageTest.java


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