JavaMail in NT
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, May 31, 2001 02:23 AM

I am working on weblogic 5.1 over windows NT. I am trying to send mail through JSP. Here is the error. I have add the mail.jar,activation.jar,mailapi.jarsmtp.jar in the classpath of windows NT through controlpanel>>system>>environment. this is the error message: reaching exceptionjavax.mail.MessagingException: IOException while sending message; nested exception is: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/html here is my code: Properties Prop = System.getProperties(); Prop.put("mail.smtp.host", mailHost); Prop.put("mail.from","from" ); Session Ses = Session.getDefaultInstance(Prop,null);    More>>

I am working on weblogic 5.1 over windows NT.

I am trying to send mail through JSP. Here is the error. I have add the mail.jar,activation.jar,mailapi.jarsmtp.jar in the classpath of windows NT through controlpanel>>system>>environment.

this is the error message:

reaching exceptionjavax.mail.MessagingException: IOException while sending message; nested exception is: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/html


here is my code:

Properties Prop = System.getProperties();
Prop.put("mail.smtp.host", mailHost);
Prop.put("mail.from","from" );
Session Ses = Session.getDefaultInstance(Prop,null);
try{
Message Mess = new MimeMessage(Ses);
javax.mail.internet.InternetAddress Addr[] = {new javax.mail.internet.InternetAddress(to)};
Mess.setRecipients(Message.RecipientType.TO, Addr);
Mess.setFrom(new InternetAddress(from));
Mess.setSubject(subject);
Mess.setContent(box, "text/html");
Transport Trans = Ses.getTransport(Addr[0]);
Trans.connect();

/*++++++++++++++HERE IS THE ERROR RAISING +++++++++*/

Trans.sendMessage(Mess, Addr);
out.println("after sending");


Any help on this?

Thank you in adv.

   <<Less

Re: JavaMail in NT

Posted By:   John_Zukowski  
Posted On:   Thursday, May 31, 2001 10:40 PM

As already mentioned in the FAQ, the mail classes that come with WebLogic are old. You need to replace them with a newer version.

Re: JavaMail in NT

Posted By:   Ivo_Limmen  
Posted On:   Thursday, May 31, 2001 03:45 AM

The setContent() method can only be used for a bodypart. The bodypart can be filled using the setText() method or setting a data handler. Furthermore, the setText() can not be used for adding HTML to your code. As soon as you set the content-id to "text/html" it expects a certain data handler; hence the error message.

Here is a simple HTMLDataSource so you can add HTML to a bodypart...

package email;

import javax.activation.DataSource;
import java.io.*;

/**
* HTMLDataSource is a data source made to supply HTML to an email message.
*/
public class HTMLDataSource implements DataSource {

private String htmlText;

/**
* Constructor.
* Creates a HTMLDataSource with all the HTML inside.
* @param newHtmlText String.
*/
public HTMLDataSource(String newHtmlText) {
super();
this.htmlText = newHtmlText;
}

/**
* Returns the content-type for the email message. It always returns text/html.
* @return String.
*/
public String getContentType() {
return "text/html";
}

public InputStream getInputStream() throws java.io.IOException {
return new ByteArrayInputStream(this.htmlText.getBytes());
}

/**
* Returns the name of this datasource.
* @return Sting.
*/
public String getName() {
return "html";
}

public OutputStream getOutputStream() throws java.io.IOException {
throw new java.lang.UnsupportedOperationException("Method getOutputStream() is not supported.");
}
}


To use this HTMLDataSource:

...
String text = "

Hi!

";
body = new MimeBodyPart();
body.setDataHandler(new DataHandler(new HTMLDataSource(text)));
...


For more information about the use of datasources and datahandlers see the JavaMail tutorial.
About | Sitemap | Contact