/*I used this and work perfectly on Tomcat on windows 2000.*/
/*for testing purpose hard code the values*/

<%@page import="java.lang.*"%>
<%@page import="java.util.*"%>
<%@page import="java.net.*"%>
<%@page import="java.io.*"%>
<%@page import="javax.mail.*"%>
<%@page import="javax.mail.internet.*"%>
<%@page import="javax.activation.*"%>

<%--Getting parameters from request--%>

<%String to = "[EMAIL PROTECTED]";%>

<%String from = request.getParameter("from");%>
<%String message = request.getParameter("Body");%>

/*for testing purpose hard code the values*/

<%--String from = "quique";--%>
<%--String message = "Message";--%>
<%String smtphost = "mail.smtp.host";%>// your smtp host here
<%String debugstr = "true";%>// for debug messages on tomcat console


<%--Passing parameters to Array z[]--%>
<% String[] z = {to, from, message, smtphost, debugstr}; %>

<%--Send the plain text message--%>
<%
      boolean debug = Boolean.valueOf(debugstr).booleanValue();

     // create some properties and get the default Session
          Properties props = new Properties();
          props.put("mail.smtp.host", smtphost);
          System.out.println(debug);
          if (debug) {
               props.put("mail.debug", debugstr);
          }

          Session sess = Session.getDefaultInstance(props, null);
          sess.setDebug(debug);

          try {
         // create a message
          Message msg = new MimeMessage(sess);
          msg.setFrom(new InternetAddress(from));
          InternetAddress[] address = {new InternetAddress(to)};
          msg.setRecipients(Message.RecipientType.TO, address);
          msg.setSubject("Feed Back. CTI italk Store");
          msg.setSentDate(new Date());
         // If the desired charset is known, you can use
         // setText(text, charset)
          msg.setText(message);

          Transport.send(msg);
     }    catch (MessagingException mex) {
          System.out.println("\n--Exception handling in
msgsendsample.java");

          mex.printStackTrace();
          System.out.println();
          Exception ex = mex;
          do {
                    if (ex instanceof SendFailedException) {
                    SendFailedException sfex = (SendFailedException)ex;
                    Address[] invalid = sfex.getInvalidAddresses();
                    if (invalid != null) {
                              System.out.println("    ** Invalid
Addresses");
                         if (invalid != null) {
                         for (int i = 0; i < invalid.length; i++)
                                   System.out.println("         " +
invalid[i]);
               }
              }
              Address[] validUnsent = sfex.getValidUnsentAddresses();
              if (validUnsent != null) {
               System.out.println("    ** ValidUnsent Addresses");
               if (validUnsent != null) {
                   for (int i = 0; i < validUnsent.length; i++)
                    System.out.println("         "+validUnsent[i]);
               }
              }
              Address[] validSent = sfex.getValidSentAddresses();
              if (validSent != null) {
               System.out.println("    ** ValidSent Addresses");
               if (validSent != null) {
                   for (int i = 0; i < validSent.length; i++)
                    System.out.println("         "+validSent[i]);
               }
              }
          }
          System.out.println();
          if (ex instanceof MessagingException)
              ex = ((MessagingException)ex).getNextException();
          else
              ex = null;
         } while (ex != null);
     }
%>

<%pageContext.setAttribute("status", "1", PageContext.REQUEST_SCOPE);%>

<jsp:forward page="name.jsp" />     //the name of the jsp that you want to
be forwarded





                    "Jorrin Ruiz de
                    Arcaute, Jorge"          To:     [EMAIL PROTECTED]
                    <[EMAIL PROTECTED]        cc:
                    >                        Subject:     SENDING JAVAMAIL
                    Sent by: A
                    mailing list
                    about Java Server
                    Pages
                    specification and
                    reference
                    <JSP-INTEREST@jav
                    a.sun.com>


                    01/30/2001 11:00
                    AM
                    Please respond to
                    A mailing list
                    about Java Server
                    Pages
                    specification and
                    reference





JavaMail works perfectly from VisualAge JAVA Editor, but as I try to
execute
it for the second time from my JSP this message is the response:
__________________________________________________________
Excepciónjavax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.IOException: No content
__________________________________________________________
Any idea? Thanks!
Here you are part of the JSP code:
___________________________________________________________
<%@ page import="SendMail" %>
<jsp:useBean id="SendMail" scope="page" class="SendMail" />
<%
try
{
        SendMail.envioMail();
} catch (Exception exception)
{
        out.print ("Oups, problem while sending message.");
}
%>
<HTML>
<head>
(...)
____________________________________________________________
And here are the envioMail() function (I promise it works perfectly on
VisualAge) of the bean. Perhaps the problem has something to be with the
session. I'm really blank. I hope anybody can help me. Regards.
____________________________________________________________
/* LLAMADA DESDE LA JSP */
public void envioMail()
{
try
{
        String host = "mail.jet.es";
        Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        Session session = Session.getDefaultInstance (props, null);
        msg = new MimeMessage(session);
        partes.add(new MimeBodyPart());
        addAddressTo("[EMAIL PROTECTED]","Gorka");
        setFrom("[EMAIL PROTECTED]","SanJorge");
        setSubject("ESTA ES LA PRUEBA 1");
        setBody("QUE YA TE HE DICHO QUE ESTA ES LA PRUEBA 1");
        send();
}catch (Exception e)
{
        System.out.println("Excepción"+e);
}
}

===========================================================================
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://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
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://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to