This is a helper class I have been using - it was actually used to send
simply notifications

This class consist of one method, so the conversion to JSP should be fairly
straightforward

- Jukkis

/*
* First install JavaMail Api - www.java.sun/products/..
* 14/10/99 : Mail.jar
*
* You will also need the JavaBeans Activation Framework extension
* or § (javax.activation). Get it from :
* http://java.sun.com/beans/glasgow/jaf.html
* 14/10/99 : Activation.jar
*/

import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;

/**
* Silly wrapper class to encapsulate mail notification routines
* Uses JavaMail-api
*/
public class MailHelper {

  /**
  * this class cannot be instantiated
  */
  private MailHelper() {
  }

  /**
  * Sends message using smtp
  *
  * @param smtpHost smtp host which is used when sending
  * @param toAddress recipients address
  * @param subject subject fields content
  * @param text content of messsage
  */
        public static void smtpSend (String smtpHost, String toAddress, String
subject, String text){
      // System properties
      Properties sysProperties = System.getProperties();
      // set smtp host
      sysProperties.put("mail.smtp.host", smtpHost); // "mail.xxxx.com"

      // mail session
      Session session = Session.getDefaultInstance(sysProperties, null);

                        try{
                          Message msg = new MimeMessage(session);
        // set recipient
        msg.setRecipient(Message.RecipientType.TO,
                         new InternetAddress(toAddress));
        // subject
        msg.setSubject(subject);
        // content, text
        msg.setText(text);
        // ??
        msg.setHeader("X-Mailer", "Content servlet");
        // sentdate
        msg.setSentDate(new java.util.Date());
        // send it!!
        Transport.send(msg);
                        } catch (MessagingException me){
                          //System.err.println(me);
        me.printStackTrace();
                        }
  }
}

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Ian Stacey
Sent: 1. maaliskuuta 2000 10:28
To: [EMAIL PROTECTED]
Subject: Email question


Hi,

I'm making a site that sends postcards, I've done most of the stuff
quite easily but need to send an email to the recipient. How do I do
this within a JSP page. I'd rather code the email functionality into the
JSP page than use servlets or beans as I don't really understand quite
how they work.

Any help would be appreciated,

Ian

---------------------------
Ian Stacey
Multimedia Author
3T Productions Ltd
http://www.3t.co.uk/
---------------------------

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
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".
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