This discussion is archived
7 Replies Latest reply: Feb 28, 2012 1:53 PM by bshannon RSS

Unable to retrieve signed mail message contents from MS outlook 2007 server

920129 Newbie
Currently Being Moderated
Hi All,

I am trying to read mail message contents from MS outlook 2007 server using IMAP protocol from my program.

But we encountering the following exceptions when we are trying to read the message contents which were sent which were signed (SSL certified)
javax.mail.MessagingException: Unable to load BODYSTRUCTURE
      at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1297)
      at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:623)
      at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1419)
The very same program was used to retrieve the message contents from MS outlook 2003 server before. Both signed and unsigned messages were read without any issues.
public static void main(String[] args) {
          // TODO Auto-generated method stub
          final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

          Properties props = new Properties();
          props.setProperty("mail.imap.port", "993");
          props.setProperty("mail.store.protocol", "imap");
          props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY);
          props.setProperty( "mail.imap.socketFactory.fallback", "false");

          try {
               Session session = Session.getDefaultInstance(props, null);
               Store store = session.getStore("imap");
               store.connect("xxxxx.com", "username", "password");
               Folder folder = store.getFolder("Inbox");
               folder.open(Folder.READ_WRITE);
               System.out.println("MessageCount---->"+folder.getMessageCount());
               Message[] messages = folder.getMessages();

               for (Message message : messages) {

                    ArrayList<String> fromList = new ArrayList<String>();
                    try {
                         for (Address address : message.getFrom()) {
                              System.out.println("Mail message from: " + address.toString());
                              fromList.add(address.toString());
                         }
                         
                         System.out.println("Content "+message.getContent());

                    } catch (Exception e) {
                         e.printStackTrace();
                    }
               } 
          }catch (NoSuchProviderException e) {
               e.printStackTrace();
               System.exit(1);
          } catch (MessagingException e) {
               e.printStackTrace();
               System.exit(2);
          }

     }
Regards,
V. Arvind

Edited by: 917126 on Feb 27, 2012 4:46 AM

Edited by: 917126 on Feb 27, 2012 6:40 AM

Legend

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