Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception While Sending Mail From Java Code

807591Feb 16 2006 — edited Apr 9 2008
Hello Everybody,

I have written a code in java for sending mail. Following is the
code:


public static void sendMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "192.168.1.12");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new
InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
System.out.println("To Address Set");
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
System.out.println("Sub and content type set");
Transport.send(msg);
}
when I run this as a seperate code it works fine. But when I
integrate it into my application Apache server gives me following exception :


PasswordReminderServlet : ProcessRequest EXC :
javax.mail.MessagingException: IO
Exception while sending message
javax.mail.MessagingException: IOException while sending message
at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:595)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at
com.emailreader.process.SMTPClient.sendMail(SMTPClient.java:50)
at
com.emailreader.web.servlet.PasswordReminderServlet.processRequest(Pa
sswordReminderServlet.java:63)
at
com.emailreader.web.servlet.PasswordReminderServlet.doPost(PasswordRe
minderServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServl
et.java:419)
at
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.jav
a:169)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH
for MIME
type text/plain
at
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:84
1)
at javax.activation.DataHandler.writeTo(DataHandler.java:295)
at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1248)
at
javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1673)
at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:555)
... 35 more

Please tell me as to what to do abt this problem

I hope u ppl reply as soon as possible.

Thanking you
sincerely,
Heti Shah
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2008
Added on Feb 16 2006
2 comments
959 views