This discussion is archived
6 Replies Latest reply: Oct 24, 2012 5:02 AM by User_Sep RSS


User_Sep Newbie
Currently Being Moderated
hi guys,
i had question. i had a mail program in java with sending attachment.
ok fine it's working good in tools like jdev,netbeans,ecliapse.

but i want to run the same program in command prompt "D:\Oracle\Middleware\jdk160_24\bin"
it's running. no error but no mail sending and no attachment sending.

so my question is:? same program in jdev can able to send mail & with attachment.
but in command prompt it doesnt work's so what would be a reason?

anything special in jdev11.
  • 1. Re: mailing
    John Stegeman Oracle ACE
    Currently Being Moderated
    Who knows? You haven't shown us your code. You haven't shown us any log messages/errors/etc
  • 2. Re: mailing
    User_Sep Newbie
    Currently Being Moderated
    no error.
    import java.util.Properties;
    import java.util.Date;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
      public class NewTest
        public static java.lang.String send() throws Exception
           String Attachment = "C:\\Users\\x.RMD\\Desktop\\x.png";
           String rc ="";
           int StartPos = 0;
           int EndPos;
           char LastAttachChar;
           String Filename;
           String operation = null;
           int s=0;
          //Check if attachment is null
          if (Attachment == null||Attachment.equals(""))
          LastAttachChar = Attachment.charAt(EndPos-1);
          //If Attachment is terminated by comma, delete the last character from attachment
          if (LastAttachChar==',')
          Attachment = Attachment.substring(StartPos,EndPos-1);
          //Get properties and default session for the SMTP server
          Properties props = System.getProperties();                      
          props.put("", "");
          props.put("mail.smtp.port", "587");
          //props.put("mail.smtp.starttls.enable", "true");
          props.put("mail.smtp.auth", "true");
          Session session = Session.getDefaultInstance(props, null);
          //Now try and create the mail message
          //Create a message
          Message msg = new MimeMessage(Session.getDefaultInstance(props, null));
          //Add sender to message
          operation = "FROM";
          //msg.setFrom(new InternetAddress(From)); 
          msg.setFrom(new InternetAddress(""));
          //Add reciepient list to message
          operation = "TO";
          //InternetAddress[] address = InternetAddress.parse(To,false);
          InternetAddress[] address = InternetAddress.parse("",false);
          msg.setRecipients(Message.RecipientType.TO, address);
          operation = "SUBJECT";
          //Add subject to message
          //Add date to message
          msg.setSentDate(new Date());
          operation = "NEW PART TO MESSAGE";
          //Add a new part to the message
          Multipart mp = new MimeMultipart();
          MimeBodyPart mbp = new MimeBodyPart();
          //Add the body to the new part
          operation = "PARSE THE ATTACHMENT";
          //Parse the attachment list and add files to the new part
          if (EndPos != 0)
          //Get the first and last positions of the file separator
          int FilesepPos     = Attachment.indexOf(",");
          int FilesepLastPos = Attachment.lastIndexOf(",");
          //The attachment contains only one file
          if (FilesepPos==-1)
          operation = "MIME";
          while (true)
          MimeBodyPart mbp = new MimeBodyPart();
          Filename = Attachment.substring(StartPos,FilesepPos);
          FileDataSource fds = new FileDataSource(Filename);
          mbp.setDataHandler(new DataHandler(fds));
          operation = "ADD BODY PART";
          if (EndPos==0)
          Attachment = Attachment.substring(FilesepPos+1,EndPos);
          EndPos = Attachment.length();
          if (FilesepPos==FilesepLastPos)
         FilesepPos    = Attachment.indexOf(",");
         FilesepLastPos = Attachment.lastIndexOf(",");
         }operation = "ATTACHMENT POSITION";
         //Add the new part to the message
         operation = "SET CONTENT";
        //Send the message
         operation = "SET TRANSPORT";
         Transport tr = session.getTransport("smtp");
         operation = "SET TRANSPORT 1";
        //tr.connect (SMTPhost, Username, Password);
         tr.connect ("", "", "dxxxxxxxx");
         operation = "CONNECT";
        //msg.setContent(Body, "text/plain");
          operation = "SAVE CHANGES";
          tr.sendMessage(msg, msg.getAllRecipients());
          operation = "SENT";
          rc = new String("Message Sent");
        //return new java.lang.String(rc);
        catch (Exception aex)
        rc = new String(aex.getMessage());
        //throw new Exception("Email Address error " + operation + " value > " + aex.getMessage());
        return new java.lang.String(rc);
            public static void main(String args[]) 
                   NewTest e = new NewTest();
                   try {
                   } catch (Exception f)
                      System.out.println("Excep" + f.getLocalizedMessage()) ;
  • 3. Re: mailing
    John Stegeman Oracle ACE
    Currently Being Moderated
    There's no error messages because you eat all exceptions and turn them into a return code, and you never print out the return code, so we have no idea what may have gone wrong.

  • 4. Re: mailing
    User_Sep Newbie
    Currently Being Moderated
    perfect answer from your previous post :)

    yes you are right absoultely. i got this exception.
    Exception in thread "main" javax.mail.MessagingException: IOException while send
    ing message;
      nested exception is:
            javax.activation.UnsupportedDataTypeException: no object DCH for MIME ty
    pe multipart/mixed; boundary="----=_Part_0_4115088.1351077337222"
            at com.sun.mail.smtp.SMTPTransport.sendMessage(
            at NewTest.send(
            at NewTest.main(
    Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME
     type multipart/mixed; boundary="----=_Part_0_4115088.1351077337222"
            at javax.activation.ObjectDataContentHandler.writeTo(
            at javax.activation.DataHandler.writeTo(
            at javax.mail.internet.MimeBodyPart.writeTo(
            at javax.mail.internet.MimeMessage.writeTo(
            at com.sun.mail.smtp.SMTPTransport.sendMessage(
            ... 2 more
    but am quite understanble with jdev.
    it's perfectly sending mail with attachment in jdev

    Edited by: Arunkumar Kootharasan on Oct 24, 2012 4:48 PM
  • 5. Re: mailing
    John Stegeman Oracle ACE
    Currently Being Moderated
    When you Google for that exception "javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;" then all will become clear
  • 6. Re: mailing
    User_Sep Newbie
    Currently Being Moderated
    john is perfect always :) as my colleague told.

    this one helped me while googling against this exception
    Re: javax.activation.UnsupportedDataTypeException:

    i found out my first mistake.
    i extracted jar. as this thread says i did it.

    second thing. i caught noclassdef error. i understood classpath is not setuped correctly.
    so i follow this

    after putting this dot and semicolon my program i identied the class path.

    now the problem solved. now i got a mail with attachment.

    atlast i conclude that, extracting jar file and classpath missing is my real problem for sending mail with attachment.

    great john hat's off brovao thousands of applause for guiding me in right way :)


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