Package javax.mail

Examples of javax.mail.Message


                                  jmFromIndex,
                                  jmToIndex);
          _folder.fetch(messages, _fetchProfile);
          for (int i = 0; i < messages.length; i++)
          {
            Message message = messages[messages.length - i - 1];
            _loaded[i + fromIndex] = new MessageData(message);
          }
        }
        finally
        {
View Full Code Here


            MailCommandManager.openFolder(aFolder, Folder.READ_ONLY);

            // add folder, too
            addResult(aFolder);

            Message msg = uidFolder.getMessageByUID(msgUID);
            addResult(msg);
        }
View Full Code Here

            MailCommandManager.openFolder(aFolder, Folder.READ_ONLY);

            // add folder, too
            addResult(aFolder);

            Message msg = aFolder.getMessage(msgId);
            addResult(msg);
        }
View Full Code Here

            // add folder, too
            addResult(aFolder);

            // get the message
            Message msg = aFolder.getMessage(msgId);

            if (msg == null) {
                String message = "Cannot get message for id " + String.valueOf(msgId);
                getLogger().warn(message);
                return;
            }
            try {
                Part part = null;
                Object objRef = msg.getContent();
                if (!(objRef instanceof Multipart)) {
                    String message = "Message of id " + String.valueOf(msgId) + " is not a multipart message!";
                    getLogger().warn(message);
                    return;
                }
View Full Code Here

        generateSAXReportStatements(iA);
    }

    private Message setUpMessage(Session session) throws Exception {
        Message sm = new MimeMessage(session);

        //sm.setAllow8bitMIME(true);
        Address[] replyTo = new Address[this.replyToAddresses.size()];
        for (int i = 0 ; i < this.replyToAddresses.size(); i++) {
            replyTo[i] = new InternetAddress((String) this.replyToAddresses.get(i));
        }
        sm.setReplyTo(replyTo);
        sm.setFrom(new InternetAddress(this.fromAddress));
        sm.setSubject(this.subject);

        // process mail-body
        BodyPart messageBodyPart = new MimeBodyPart();

        // decide, if to take content from source or plain text
        // from variable to build mailbody
        String messageString;
        if (this.bodyURI != null) {
            Source      inSrc   = resolver.resolveURI(this.bodyURI);
            this.usedSources.add(inSrc);
            InputStream inStr   = inSrc.getInputStream();
            byte[]      byteArr = new byte[inStr.available()];
            inStr.read(byteArr);
           
            messageString = new String(byteArr);
           
            // String mailBody = new String(byteArr);
            // this.setMessageBody(messageBodyPart, mailBody, this.bodyMimeType);
        } else {
            messageString = this.body;
            // this.setMessageBody(messageBodyPart, this.body, this.bodyMimeType);           
        }

        // make it a simple plain text message in the case of a set plain/text
        // mime-type and any attachements
        if("text/plain".equals(this.bodyMimeType) && this.attachments.size() == 0) {    
            sm.setText(messageString);
        }
        // add message as message body part
        else {
            messageBodyPart.setContent(messageString, this.bodyMimeType);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);

            // process attachments
            Iterator i = this.attachments.iterator();
            while (i.hasNext()) {
                AttachmentDescriptor aD = (AttachmentDescriptor) i.next();
                messageBodyPart = new MimeBodyPart();
   
                if (!aD.isTextContent()) {
                    Source inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc : aD.strAttrFile);
                    this.usedSources.add(inputSource);
   
                    DataSource dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType, aD.strAttrName);

                    messageBodyPart.setDataHandler(new DataHandler(dataSource));
                } else {
                    messageBodyPart.setContent(aD.strContent, aD.strAttrMimeType);
                }
   
                messageBodyPart.setFileName(aD.strAttrName);
                multipart.addBodyPart(messageBodyPart);
            }
            sm.setContent(multipart);
        }

        //sm.setReturnOption(SMTPMessage.RETURN_FULL);
        sm.saveChanges();

        return sm;
    }
View Full Code Here

    /**
     * Extracts the body from the Mail message
     */
    public Object extractBodyFromMail(Exchange exchange, MailMessage mailMessage) {
        Message message = mailMessage.getMessage();
        try {
            return message.getContent();
        } catch (Exception e) {
            // try to fix message in case it has an unsupported encoding in the Content-Type header
            UnsupportedEncodingException uee = ObjectHelper.getException(UnsupportedEncodingException.class, e);
            if (uee != null) {
                LOG.debug("Unsupported encoding detected: " + uee.getMessage());
                try {
                    String contentType = message.getContentType();
                    String type = ObjectHelper.before(contentType, "charset=");
                    if (type != null) {
                        // try again with fixed content type
                        LOG.debug("Trying to extract mail message again with fixed Content-Type: " + type);
                        // Since message is read-only, we need to use a copy
View Full Code Here

    protected void assertMailboxReceivedMessages(String name) throws Exception {
        Mailbox mailbox = Mailbox.get(name);
        assertEquals(name + " should have received 1 mail", 1, mailbox.size());

        Message message = mailbox.get(0);
        assertNotNull(name + " should have received at least one mail!", message);
        Object content = message.getContent();
        assertNotNull("The content should not be null!", content);
        if (content instanceof InputStream) {
            assertEquals("hello world!", IOConverter.toString((InputStream)content, null));
        } else {
            assertEquals("hello world!", message.getContent());
        }
        assertEquals("camel@localhost", message.getFrom()[0].toString());
        boolean found = false;
        for (Address adr : message.getRecipients(RecipientType.TO)) {
            if (name.equals(adr.toString())) {
                found = true;
            }
        }
        assertTrue("Should have found the recpient to in the mail: " + name, found);
View Full Code Here

        + config.getProperty("user.name")
        + ":\n\n"
        + "You have successfully ingested the file with the following metadata: \n\n"
        + getMsgStringFromMet(metadata) + "\n\n" + "Thanks!\n\n" + "CAS";

    Message msg = new MimeMessage(session);
    try {
      msg.setSubject(config.getProperty("msg.subject"));
      msg.setSentDate(new Date());
      msg.setFrom(InternetAddress.parse(config.getProperty("mail.from"))[0]);
      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(config
          .getProperty("mail.to"), false));
      msg.setText(msgTxt);
      Transport.send(msg);

    } catch (MessagingException e) {
      throw new WorkflowTaskInstanceException(e.getMessage());
    }
View Full Code Here

            }              
            Session session = Session.getInstance( props, null );
            session.setDebug( debug );
           
            // construct the message
            Message msg = new MimeMessage( session );
           
            msg.setFrom( new InternetAddress( from ) );
            msg.setReplyTo( new InternetAddress[] {  new InternetAddress( replyTo ) }  );
           
            for ( Recipient recipient : message.getRecipients().getRecipients() ) {
                RecipientType type = null;
                if ( "To".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.TO;
                } else if ( "Cc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.CC;
                } else if ( "Bcc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.BCC;
                } else {
                    throw new RuntimeException( "Unable to determine recipient type" );
                }

                msg.addRecipients( type, InternetAddress.parse( recipient.getEmail(), false ) );
            }
            msg.setSubject( subject );
            collect( message.getBody(), msg );
            msg.setHeader( "X-Mailer", mailer );
            msg.setSentDate( new Date() );
           
            // send the thing off
          Transport t = (Transport)session.getTransport("smtp");
          try {
            t.connect(mailhost, username, password);
          t.sendMessage(msg, msg.getAllRecipients());
          } catch (Exception e) {
            throw new RuntimeException( "Connection failure", e );
           } finally {
            t.close();
          }
View Full Code Here

                }
            });
            mailSession.setDebug(false);

            //CONFIG. DA MENSAGEM
            Message mailMessage = new MimeMessage(mailSession);

            //REMETENTE
            mailMessage.setFrom(new InternetAddress(emailRemetente));

            //DESTINATARIO
            mailMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailDestinatario));       

            //MENSAGEM QUE VAI NO CORPO DO EMAIL
            MimeBodyPart mbpMensagem = new MimeBodyPart();
            mbpMensagem.setText(mensagem);

            //PARTES DO EMAIL
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbpMensagem);
           

            //ASSUNTO DO EMAIL
            mailMessage.setSubject(assunto);
           
            //SELECIONA O CONTEUDO
            mailMessage.setContent(mp);

            //ENVIA O EMAIL
            Transport.send(mailMessage);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of javax.mail.Message

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.