This discussion is archived
1 Reply Latest reply: Jun 5, 2013 12:33 PM by bshannon RSS

Receiving multipart messages for a text/plain content type

1012872 Newbie
Currently Being Moderated
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
  • 1. Re: Receiving multipart messages for a text/plain content type
    bshannon Pro
    Currently Being Moderated
    I assume the code you've posted is the code you're using to send the message.

    How do you know for sure that the message you sent is not a multipart message?
    Have you looked at the debug output or written the message to a file to prove that
    it's a plain text message?

    How are you reading the message? What mail server are you using?

    You say you're using SMS, but I don't see how SMS fits into the picture.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points