Error occured during attachment of file using java.
I want to attach some files using java in my Email Application.SO i used Multipart class but i got some error like this.....
Code :
Exception caught
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_31510384.1309567547673"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:625)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at MultipartExample.<init>(MultipartExample.java:43)
at MultipartExample.main(MultipartExample.java:53)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_31510384.1309567547673"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:891)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
... 4 more
Re: Error occured during attachment of file using java.
This thread may help (from googling for 'no object DCH for MIME type multipart/mixed').
I don't usually act like a Google front-end, but I'm in a good mood...
Re: Error occured during attachment of file using java.
@dlorde I have done lot of googling but still i am not able to fix the error can you tell me how to fix that issue.
Please i have to do continue my project help me guy's !!
Re: Error occured during attachment of file using java.
So did none of the solutions in the thread I linked to work?
Please post up the code you tried for them.
Re: Error occured during attachment of file using java.
yeh why not.....actually i am trying to do a simple Multipart program
check this code...
Quote:
import java.util.Properties;
/*import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.PasswordAuthentication;
import javax.mail.Authenticator;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.Multipart;
import javax.mail.MimeMultipart;
import javax.mail.BodyPart;
import javax.mail.MimeBodyPart;*/
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class MultipartExample
{
MultipartExample()
{
try
{
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host","smtp.gmai l.com");
properties.setProperty("mail.smtp.port","587");
properties.setProperty("mail.smtp.auth","true");
properties.setProperty("mail.smtp.starttls.enable" ,"true");
Session session=Session.getDefaultInstance(properties,new MyAuthentication());
Message message=new MimeMessage(session);
message.setFrom(new InternetAddress("morning.com.hablu@gmail.com"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress("kaliyaodi@gmail.com"));
message.setSubject("Multipart message");
Multipart multipart=new MimeMultipart();
BodyPart bodypart=new MimeBodyPart();
bodypart.setText("Can you get this message....?");
bodypart.setDataHandler(new DataHandler("hiiiii","text/plain"));
//BodyPart bodypart1=new MimeBodyPart();
//bodypart1.setText("My name is");
multipart.addBodyPart(bodypart);
//message.setContent(multipart,"text/html; charset=UTF-8");
//multipart.addBodyPart(bodypart1);
//message.setContent("hekkdjjdj", "text/html; charset=UTF-8");
message.setContent(multipart);
Transport.send(message);
}
catch(Exception e)
{
System.out.println("Exception caught ");
e.printStackTrace();
}
}
public static void main(String args[])
{
new MultipartExample();
}
class MyAuthentication extends Authenticator
{
MyAuthentication()
{
super();
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("morning.com.hablu","rockan dhack");
}
}
}
But don't know why it will throw the above exception.
Help me please !!
Re: Error occured during attachment of file using java.
OK - you clearly aren't going to tell me what you tried from the link, so let's do it the long way:
1 - did you make sure mail.jar and activation.jar and in your appserver are compatible versions ? (this seems to be the most common problem)
2 - are the jars in the same directory?
3 - the code you posted doesn't show the MailCap MIME handler initialization - did you try that - can you post the code you used for it?
p.s. this is my last attempt, I really don't have the time to mess about.