Results 1 to 2 of 2
  1. #1
    sniffer139 is offline Member
    Join Date
    Feb 2010
    Posts
    19
    Rep Power
    0

    Post exeption haldling

    below is my snippet where i am trying to attach a file n send through java...if i attach a file den d mail will go,,if i wont attach a file den exception occurs even after putting the code wr i just want to print my body part.kindly plz help out



    try
    {

    if(src!=null) // code wr i attach a file
    {

    MimeBodyPart p1 = new MimeBodyPart();
    text=jTextArea6.getText();
    p1.setText(text);
    MimeBodyPart p2 = new MimeBodyPart();
    p2.attachFile(src);
    p2.setHeader("Content-Type","multipart/mixed");
    src=atttxt.getText();
    //String data = "any ASCII data";
    //DataSource fds = new ByteArrayDataSource(data, "application/x-any");
    FileDataSource fds = new FileDataSource(src);
    p2.setDataHandler(new DataHandler(fds));
    p2.attachFile(src);
    p2.setFileName(fds.getName());
    //p2.setDisposition(MimeBodyPart.ATTACHMENT);
    // p2.addHeader("Content-type", "text/plain; charset=us-ascii");
    p2.setHeader( "content-type","Content-Transfer-Encoding: BASE64") ;
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(p1);
    mp.addBodyPart(p2);
    msg.setContent(mp);
    msg.setSubject(subject);
    msg.setDisposition(src);
    charset="iso-8859-1";
    msg.setHeader("content-type","text/plain");
    msg.setFileName(src);
    msg.setText(text);
    }

    }

    catch (MessagingException mex) {
    mex.printStackTrace();
    Exception ex = null;
    if ((ex = mex.getNextException()) != null) {
    ex.printStackTrace();
    }
    }
    finally

    {
    msg.setSubject(subject); // here i just want ro send a body part
    msg.setText(text);
    }



    pls check out whether my code is correct
    SNIFFER

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    First, put your code in CODE tags, otherwise the formatting disappears and it becomes a lot harder to read.

    Second, please don't use text speak...that also makes things harder to read and makes you look like a simpleton.

Similar Threads

  1. null pointer exeption
    By mj23brm in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •