5 Replies Latest reply on Feb 26, 2003 2:34 PM by Srinivasu

    Sending mail from JSP

    Srinivasu Newbie

      Hi,

      I was wondering if anybody can point to sample code for sending mail from a JSP in JBoss3.0.6.

      Any response would be greatly appreciated.

      Sony

        • 1. Re: Sending mail from JSP
          Suraj Amin Newbie

          Hi,

          You could use the mailer taglib from Jakarta Taglibs:
          http://jakarta.apache.org/taglibs/doc/mailer-doc/intro.html

          Documentation + Sample Code:
          http://jakarta.apache.org/taglibs/doc/mailer-doc/

          --
          Regards,
          Suraj Amin

          Homepage: http://www.geocities.com/suraj_amin/

          /* It is impossible to defeat an ignorant man in argument. */

          • 2. Re: Sending mail from JSP
            Achilleus Mantzios Newbie

            Here is how

            String from, to, etc...;
            java.util.Properties propz = System.getProperties();

            propz.put("mail.smtp.host","yourmailhost.net");
            propz.put("mail.smtp.port","25");
            Session sess = Session.getDefaultInstance(propz,null);
            MimeMessage msg = new MimeMessage(sess);
            msg.setFrom(new InternetAddress(from));
            msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
            msg.addRecipient(Message.RecipientType.CC,new InternetAddress(cc));
            msg.setSubject(subject);
            MimeMultipart mp = new MimeMultipart("related");
            MimeBodyPart bp = new MimeBodyPart();
            bp.setText(body);
            mp.addBodyPart(bp);
            bp = new MimeBodyPart();
            String staturl = ...;
            bp.setDataHandler(new DataHandler(new URLDataSource(new java.net.URL(staturl))));

            bp.addHeaderLine("Content-Type: text/html; charset=\"iso-8859-1\"");

            bp.addHeaderLine("Content-Location: "+staturl);
            bp.setFileName("FOO_STATUS.html");


            mp.addBodyPart(bp);


            msg.setContent(mp);

            • 3. Re: Sending mail from JSP
              Srinivasu Newbie

              Hi,

              Thank you for the reply.
              I have had a problem few days back when tryign to do that.
              At the line, MimeMessage msg = new MimeMessage(sess), it threw an exception saying it cannot find javax.activation.DataSource.
              I did put activation.jar in the class and took a print out if the system classpath just before this statement also.

              After one whole days struggle I figured out that it is not sufficient if I add it to classpath, I need to put it in jre/lib/ext and then it worked.

              I am posting this so that anybody else who might be facing the same problem could use the effort.

              sony

              • 4. Re: Sending mail from JSP
                Achilleus Mantzios Newbie

                the jar located at /usr/local/jboss-3.0.3/server/default/lib/activation.jar
                should be just fine.

                In which ..../lib/ext did you put the jar in??

                • 5. Re: Sending mail from JSP
                  Srinivasu Newbie

                  No, the server/default/lib did not work.
                  I had to put it in $JAVA_HOME/jre/lib/ext for it to work.

                  Sony