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

}


--------------------------------

Taro

===========================================================================
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

===========================================================================
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

===========================================================================
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

Reply via email to