Package javax.mail.internet

Examples of javax.mail.internet.MimeMessage


           
            @Override
            protected void invokeApplication() throws Exception
            {
                Contexts.getEventContext().set("name", "Pete\nMuir");  
                MimeMessage renderedMessage = getRenderedMailMessage("/org/jboss/seam/example/mail/test/sanitization.xhtml");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "peter@email.tld");
                Assert.assertEquals(to.getPersonal(), "Pete");
                Assert.assertEquals(renderedMessage.getFrom().length, 1);
                Assert.assertTrue(renderedMessage.getFrom()[0] instanceof InternetAddress);
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "peter@example.com");
                Assert.assertEquals(from.getPersonal(), "Pete");
                Assert.assertNotNull(renderedMessage.getHeader("Pete"));
                Assert.assertEquals(renderedMessage.getHeader("Pete").length, 1);
                Assert.assertEquals(renderedMessage.getHeader("Pete")[0], "roll over");
            }
        }.run();
    }
View Full Code Here


            }
           
            @Override
            protected void invokeApplication() throws Exception
            {  
                MimeMessage renderedMessage = getRenderedMailMessage("/templating.xhtml");
            
                // Test the standard headers
               
                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
                Assert.assertEquals(to.getAddress(), "test@example.com");
                Assert.assertEquals(to.getPersonal(), "Pete Muir");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Templating with Seam Mail");
                Assert.assertNull(renderedMessage.getHeader("X-Priority"));
                Assert.assertNull(renderedMessage.getHeader("Priority"));
                Assert.assertNull(renderedMessage.getHeader("Importance"));
               
                // Check the body
               
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
               
                // Check the alternative facet
                Assert.assertTrue(renderedMessage.getContentType().startsWith("multipart/mixed"));
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertTrue(bodyPart.getContentType().startsWith("multipart/alternative"));
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                MimeMultipart bodyParts = (MimeMultipart) bodyPart.getContent();
View Full Code Here

                    FolderUtil.getFileExt(item.getFilename()));
                DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
                attachment.setDataHandler(new DataHandler(ds));
                mp.addBodyPart(attachment);
            }
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(fromAddress, fromText));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(toAddress, toAddress));
            msg.setSubject(subject, "UTF-8");
            msg.setContent(mp);
            Transport.send(msg);
            return null;
        } catch (AddressException e) {
            return e.getMessage();
        } catch (MessagingException e) {
View Full Code Here

      
   }
 
//--------------------------------------------------------------------------------createMessage
   public void createMessage(Session session) throws Exception {
      message = new MimeMessage(session);     
   }
View Full Code Here

   
    public void loadFile(File messageFile) throws Exception  {
     FileInputStream  messageInputStream= null;
         try {
            messageInputStream = new FileInputStream(messageFile);
            message = new MimeMessage( createSession(), messageInputStream );
            loadedMessageId = message.getMessageID();
           
            raw_email_byte_stream = new ByteArrayOutputStream();    
            message.writeTo( raw_email_byte_stream );
            messageBytes = raw_email_byte_stream.toByteArray();
View Full Code Here

//  --------------------------------------------------------------------------------messageRemoveAttachments
    private ByteArrayOutputStream messageRemoveAttachments() throws Exception{
      ByteArrayOutputStream raw_email_byte_stream_without_attachment = new ByteArrayOutputStream();
      
//      Attachments entfernen
        MimeMessage mm = new MimeMessage(message);
        Object mmpo=mm.getContent();
        if (  ( mmpo instanceof MimeMultipart ) ){
          MimeMultipart mmp= (MimeMultipart) mmpo;
     
           if (mm.isMimeType("text/plain")) {
            } else if (mm.isMimeType("multipart/*")) {
              mmp=(MimeMultipart)mm.getContent();
             for (int i = 1; i < mmp.getCount(); i++) {
                BodyPart part = mmp.getBodyPart(i);
              mmp.removeBodyPart(i);
               i--;
              }
          
           } 

//        
           mm.setContent(mmp);
          mm.saveChanges();     
           
       mm.writeTo(raw_email_byte_stream_without_attachment);
       return raw_email_byte_stream_without_attachment;
      
     }
View Full Code Here

     */
    public SOSMimeMessage getAttachedSosMimeMessage(Session session, byte[] messageContent) throws Exception {
        if (messageContent == null)
            throw new Exception("messageContent has null value!!");
         InputStream  messageInputStream = new ByteArrayInputStream(messageContent);
         return new SOSMimeMessage(new MimeMessage( session, messageInputStream ),this.getLogger());
    }
View Full Code Here

        // Setup the smtp mail server
        session.getProperties().put("mail.smtp.host", smtpHost);
       
        session.getProperties().put("mail.smtp.port", smtpPort);

        MimeMessage forward = new MimeMessage(session);
       
        forward.setSubject("Fw. "+message.getSubject());
       
        forward.setFrom(new InternetAddress(mailFrom));
       
        for(int i=0;i<toArray.length;i++) {
          forward.addRecipient(Message.RecipientType.TO, new InternetAddress(toArray[i]));
        }
       
        for(int i=0;i<ccArray.length;i++) {
            forward.addRecipient(Message.RecipientType.CC, new InternetAddress(ccArray[i]));
        }

        for(int i=0;i<bccArray.length;i++) {
            forward.addRecipient(Message.RecipientType.BCC, new InternetAddress(bccArray[i]));
        }
      
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(forwardSubject);

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();
        messageBodyPart.setDataHandler(message.getDataHandler());

        multipart.addBodyPart(messageBodyPart);

        forward.setContent(multipart);

        Transport.send(forward);
       
       }//forwardMessage
View Full Code Here

        session = Session.getDefaultInstance(props, null);
      }


      // -- Create a new message --
      Message msg = new MimeMessage(session);

      // -- Set the FROM and TO fields --
      msg.setFrom(new InternetAddress(from));
      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
          to, false));

      // -- We could include CC recipients too --
      // if (cc != null)
      // msg.setRecipients(Message.RecipientType.CC
      // ,InternetAddress.parse(cc, false));

      // -- Set the subject and body text --
      msg.setSubject(subject);
      msg.setDataHandler(new DataHandler(new ByteArrayDataSource(body,
          "text/html; charset=\"utf-8\"")));

      // -- Set some other header information --
      msg.setHeader("X-Mailer", "XML-Mail");
      msg.setSentDate(new Date());

      // -- Send the message --
      Transport.send(msg);

      return "success";
View Full Code Here

   
    List<WiserMessage> messages = wiser.getMessages();
    assertEquals(1, messages.size());
   
    WiserMessage message = messages.get(0);
    MimeMessage mimeMessage = message.getMimeMessage();
   
    assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null));
    assertEquals("\"" + from + "\" <" +from.toString() + ">" , mimeMessage.getHeader("From", null));
    assertTrue(mimeMessage.getHeader("To", null).contains(recipient));
  }
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.