Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to receive mail attachments using Java Mail in Jdeveloper

3277898Jul 18 2016 — edited Jul 19 2016

I am trying to deploy an Oracle MAF app to the iOS platform. I am using Java Mail to receive emails from the gmail server. I am trying to to identify mails that have attachments. However I get the following error.

java.lang.ClassCastException: com.sun.mail.imap.IMAPInputStream cannot be cast to javax.mail.Multipart

When I identify the mime type of the message as "multipart/mixed", I am trying to cast the object into Multipart.

I understand that this question has been asked before but I have tried to implement the solution proposed here. However I am unable to import anything from javax.activation. The error that I get in jdeveloper is

Error : javax.activation.CommandMap is not available in the profile.

This error shows up for everything from javax.activation

Also, this error pops up only in an MAF application. It works well in a normal java project.

Here is my code

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;

public class Email {
  public Email()
  {

  String userName = "abc@gmail.com";
  String password = "password";
  String receivingHost;

  receivingHost="imap.gmail.com";

  Properties props=System.getProperties();
  props.setProperty("mail.store.protocol", "imaps");

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

  try
  {
  Store store=session.getStore("imaps");
  store.connect(receivingHost,userName, password);
  Folder folder=store.getFolder("INBOX");
  folder.open(Folder.READ_ONLY);
  Message messages[]=folder.getMessages();

  //System.out.println(messages.length);
  for (Message message : messages)
  {
  if(message.isMimeType("multipart/mixed"))
  {
  Multipart mp = (Multipart)message.getContent();
  //get content 
  }
  else
  {
  //getcontent
  }
  }

  store.close();

  }
  catch (Exception e)
  {
  System.out.println(e.toString());
  }
  //System.out.println("Done");
  }
}

Comments
Post Details
Added on Jul 18 2016
4 comments
1,078 views