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

Reply via email to