javax.activation.UnsupportedDataTypeException

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top