1 Reply Latest reply: Jun 5, 2013 2:33 PM by Bill Shannon-Oracle RSS

    Receiving multipart messages for a text/plain content type

    1012872
      Mail format is plain and the content type is text/plain.But I am receiving multipart/mixed messages via sms ,instead of a plain text.

      ------=_Part_6_1271882243.1366881315032
      Content-Type: text/plain; charset=UTF-8
      Content-Transfer-Encoding: 7bit

      D: $displayName
      ------=_Part_6_1271882243.1366881315032--


      //CODE

      Properties resultProps = new Properties();
           try {
           // create a message
           MimeMessage msg = new MimeMessage(session);
           msg.setFrom(new InternetAddress(fromAddr));
           InternetAddress[] address = new InternetAddress[toAddr.length];
           String toList = "";
           for(int i=0;i<toAddr.length;i++)
           {
                address[i] = new InternetAddress(toAddr);
                toList += address[i] + ",";
           }
           msg.setRecipients(Message.RecipientType.TO, address);
           msg.setSubject(subject,"UTF-8"); //No I18N
           msg.setSentDate(new Date());
           if(mailFormat.equals(both_MAILFORMAT))
           {
                Multipart multipart = new MimeMultipart("alternative"); //No I18N
                MimeBodyPart messageBodyPart = new MimeBodyPart();
                messageBodyPart.setText(message,"UTF-8"); //No I18N
                multipart.addBodyPart(messageBodyPart);
                if(htmlMessage!=null)
                {
                messageBodyPart = new MimeBodyPart();
                messageBodyPart.setContent(htmlMessage, "text/html; charset=UTF-8"); //No I18N
                multipart.addBodyPart(messageBodyPart);
                }
                msg.setContent(multipart);
           }
           else if(mailFormat.equals(plain_MAILFORMAT))
           {     
           msg.setText(message); //No I18N
      if(fileAttachment != null)
           {
           StringTokenizer st = new StringTokenizer(fileAttachment,","); //No Internationalization
           MimeBodyPart messageBodyPart = new MimeBodyPart();
           messageBodyPart.setText(message,"UTF-8"); //No I18N

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

           while(st.hasMoreTokens())
           {
           String fileUrl = st.nextToken();
      DataSource source = new FileDataSource(fileUrl);
           MimeBodyPart messageBodyPart2 = new MimeBodyPart();
           messageBodyPart2.setDataHandler(new DataHandler(source));
           String fileName = MimeUtility.encodeWord(file.getName(), "UTF-8", "B"); //No I18N
           messageBodyPart2.setFileName(fileName);

           multipart.addBodyPart(messageBodyPart2);
           }
           msg.setContent(multipart);
           }
           }
           else
           {
                if(htmlMessage!=null)
                {
                msg.setContent(htmlMessage, "text/html; charset=UTF-8"); //No I18N
                }
                else
                {

                msg.setContent(message, "text/html; charset=UTF-8"); //No I18N

           msg.saveChanges();
           Transport transport = session.getTransport("smtp"); //No Internationalization
           transport.connect( serverAddr , userName, password );
           transport.sendMessage(msg, msg.getAllRecipients());
           transport.close();
           notificationLogs.log("Mail sent to " + toList + ". Subject : " + subject, Log.DEBUG); //No I18N