Hi Ritesh and everyone else who knows about JavaMail,
I've tried pretty much everything to get my code to work, but even with the
successful compiration, the page doesn't work at all. Instead, I get an
internal error shown in below. Is there anything I can do?
Taro
----------------------------------------------------------
Error: 500
Location: /taiken/servlet/SendMail
Internal Servlet Error:
java.lang.NullPointerException
at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:98)
at
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
at javax.activation.DataHandler.writeTo(DataHandler.java:295)
at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:222)
at
javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1065)
at
javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1914)
at
javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1895)
at javax.mail.Transport.send(Transport.java:79)
at SendMail.doGet(SendMail.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:81
2)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection
(Ajp12ConnectionHandler.java:166)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
-----Original Message-----
From: Ritesh Gupta [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 4:44 PM
To: [EMAIL PROTECTED]
Subject: Re: JavaMail in servlet 2
Hi Taro,
I tried your code with the doGet method, that is the only change I
made. As far as html tags are concerned, you should get an output
even if they are not corrected. I got some runtime Exception while
execution of your java code in the servlet.
The only other issue I could find (which would have been found
when you compiled the servlet) was the first line :
iimport java.io.*;
There is a typo here with the import statement.
Ensure that your servlet is properly re-compiled and replaces your
earlier servlet.
To ensure whether any servlet is getting called at all you could
try with another sample Servlet. Maybe the foll :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
res.setContentType("text/html; charset=\"iso-2022-jp\"");
PrintWriter out = res.getWriter();
out.println("Ritesh is mad");
out.close();
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
res.setContentType("text/html; charset=\"iso-2022-jp\"");
PrintWriter out = res.getWriter();
out.println("Ritesh is totally insane");
out.close();
}
}
Regards,
Ritesh
----- Original Message -----
From: Taro Kondo <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 23, 2002 12:56 PM
Subject: Re: JavaMail in servlet 2
Thank you both of you!
However, with the two corrections, the page in the browser still says, "Page
cannot be found". Why is that?
What I have changes is replace Post with Get, but is there anything else to
do beside that?
Please let me know.
Taro
public class SendMail extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
-----Original Message-----
From: Ritesh Gupta [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 4:10 PM
To: [EMAIL PROTECTED]
Subject: Re: JavaMail in servlet 2
Hi Taro,
By default the request that goes to the servlet when you invoke
it from the browser is GET. Modify (or add) your code to the
doGet method and try.
Hope that helps.
Regards,
Ritesh
----- Original Message -----
From: Taro Kondo <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 23, 2002 12:21 PM
Subject: JavaMail in servlet 2
I have a question in JavaMail.
I don't know why the page generated by servlet doesn't even show up even the
java file was compiled successfully. I mean even though JavaMail function
doesn't work properly, at lease the html part should show up in the page...
Does anyone know why it doesn't work with this code?
Please help me!
--- Here is the code ---
iimport java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMail extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
res.setContentType("text/html; charset=\"iso-2022-jp\"");
PrintWriter out = res.getWriter();
out.println("<html><head><title>");
out.println("Send Mail");
out.println("</html></head></title><h3>");
out.println("Send Mail");
out.println("</h3>");
try {
Properties props = new Properties();
props.put("mail.smtp.host","my.mail.server");
props.put("mail.host","my.mail.server");
props.put("mail.user","servbook");
Session session = Session.getInstance(props,null);
MimeMessage msg = new MimeMessage(session);
InternetAddress[] tolist = new InternetAddress[2];
tolist[0] = new InternetAddress("[EMAIL PROTECTED]",
MimeUtility.encodeWord("recipient 1","iso-2022-jp","B"));
tolist[1] = new InternetAddress("[EMAIL PROTECTED]",
MimeUtility.encodeWord("recipient 2","iso-2022-jp","B"));
msg.setRecipients(Message.RecipientType.TO,tolist);
msg.setFrom(new InternetAddress("[EMAIL PROTECTED]",
MimeUtility.encodeWord("sender","iso-2022-jp","B")));
String subject = "sent from servlet";
msg.setSubject(MimeUtility.encodeText(subject,"iso-2022-jp","B"));
String content = req.getParameter("content");;
msg.setContent(content,"text/plain;
charset=\"iso-2022-jp\"");
Transport.send(msg);
out.println("<p>mail is sent</p>");
out.println("<pre>");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
msg.writeTo(bos);
bos.close();
out.println(bos.toString("ISO2022JP"));
out.println("</pre>");
} catch (MessagingException ex) {
out.println("<p>fail to send mail</p>");
}
out.println("</body></html>");
out.close();
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com