K
Krishna
Hello,
I have the foolowing method to send an email with an attachment. When
I run it from my IDE (Eclipse) the code works fine sends email with
required attachment.
But when I run the same from a server using javawebstart it throws
following exception :
IOException while sending
message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH
for MIME type multipart/mixed;
Any ideas?
Thanks
Krishna
Here is the method :
public void sendMessageWithAttachedFile() throws Exception
{
if(toList.size() == 0 && ccList.size() == 0 && bccList.size() == 0)
{
throw new Exception("No recipient list");
}
Message msg = new MimeMessage(Session.getDefaultInstance(System.getProperties(),null));
msg.setFrom(new InternetAddress(from));
for(int i=0; i<toList.size(); i++)
{
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress((String)toList.get(i)));
}
for(int i=0; i<ccList.size(); i++)
{
msg.addRecipient(Message.RecipientType.CC, new
InternetAddress((String)ccList.get(i)));
}
for(int i=0; i<bccList.size(); i++)
{
msg.addRecipient(Message.RecipientType.BCC, new
InternetAddress((String)bccList.get(i)));
}
msg.setSubject(subject);
msg.setSentDate(new Date());
InternetAddress iAddress;
System.out.println("Emailing to: ");
for(int i=0;i<toList.size();i++)
{
iAddress = new InternetAddress((String)toList.get(i));
System.out.println("\t" + iAddress);
}
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
//create and fill the first message part (body)
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
mp.addBodyPart(mbp1);
if (!attachedFile.equals(""))
{
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(attachedFile);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
}
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
}
I have the foolowing method to send an email with an attachment. When
I run it from my IDE (Eclipse) the code works fine sends email with
required attachment.
But when I run the same from a server using javawebstart it throws
following exception :
IOException while sending
message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH
for MIME type multipart/mixed;
Any ideas?
Thanks
Krishna
Here is the method :
public void sendMessageWithAttachedFile() throws Exception
{
if(toList.size() == 0 && ccList.size() == 0 && bccList.size() == 0)
{
throw new Exception("No recipient list");
}
Message msg = new MimeMessage(Session.getDefaultInstance(System.getProperties(),null));
msg.setFrom(new InternetAddress(from));
for(int i=0; i<toList.size(); i++)
{
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress((String)toList.get(i)));
}
for(int i=0; i<ccList.size(); i++)
{
msg.addRecipient(Message.RecipientType.CC, new
InternetAddress((String)ccList.get(i)));
}
for(int i=0; i<bccList.size(); i++)
{
msg.addRecipient(Message.RecipientType.BCC, new
InternetAddress((String)bccList.get(i)));
}
msg.setSubject(subject);
msg.setSentDate(new Date());
InternetAddress iAddress;
System.out.println("Emailing to: ");
for(int i=0;i<toList.size();i++)
{
iAddress = new InternetAddress((String)toList.get(i));
System.out.println("\t" + iAddress);
}
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
//create and fill the first message part (body)
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(body);
mp.addBodyPart(mbp1);
if (!attachedFile.equals(""))
{
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(attachedFile);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
}
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
}