Results 1 to 3 of 3
  1. #1
    heman is offline Member
    Join Date
    Aug 2012
    Posts
    39
    Rep Power
    0

    Default Email not being sent with attachment but working fine without attachment.

    Hello every one,
    I am trying to send email with attachment using java mail API.
    My emails works perfectly and the message is sent without attachment, but when I add some attachment there exists an exception saying :

    Java Code:
    javax.mail.MessagingException: IOException while sending message;
      nested exception is:
    	java.io.IOException: No content
    The code i used to get selected file from clicking a button is :
    Java Code:
     JFileChooser jfc=new JFileChooser(".");
    			int result=	jfc.showOpenDialog(this);
    			
    			if(result==JFileChooser.APPROVE_OPTION)
    			{
                     		      filename=jfc.getSelectedFile().getPath();
                                }
    And code for attachment is this :
    Java Code:
                             Multipart body=new MimeMultipart();
    			 MimeBodyPart part1=new MimeBodyPart();
    			
    			body.addBodyPart(part1);
    			MimeBodyPart part2=new MimeBodyPart();
    			
    		
    			FileDataSource fds=new FileDataSource(filename);
    			
    			part2.setDataHandler(new DataHandler(fds));
    			part2.setFileName(fds.getName());
    			body.addBodyPart(part2);
    			message.setContent(body);
    Can any body please help me out.
    Thanks and Regards,
    heman

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

    Default Re: Email not being sent with attachment but working fine without attachment.

    Why do you have an empty body part for part1?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    heman is offline Member
    Join Date
    Aug 2012
    Posts
    39
    Rep Power
    0

    Default Re: Email not being sent with attachment but working fine without attachment.

    Quote Originally Posted by Tolls View Post
    Why do you have an empty body part for part1?
    Thanks for response.I initially set text in part1 but afterwards removed it and forgot.
    Thanks again.

Similar Threads

  1. Soap attachment using axis 1.4
    By RajeshPro in forum Web Frameworks
    Replies: 2
    Last Post: 01-10-2013, 01:59 PM
  2. SOAP application with File Attachment
    By Ajitha in forum New To Java
    Replies: 0
    Last Post: 10-08-2010, 05:56 AM
  3. Getting link attachment
    By dynamolalit in forum Advanced Java
    Replies: 0
    Last Post: 08-17-2009, 12:03 PM
  4. Problems with saaj and attachment
    By seare in forum Advanced Java
    Replies: 0
    Last Post: 07-20-2009, 02:29 PM
  5. Mail Attachment as Source
    By vinoopraj in forum Advanced Java
    Replies: 2
    Last Post: 06-15-2009, 07:21 AM

Posting Permissions

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