tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shahid....@iname.com
Subject Re: EMail from a Servlet
Date Fri, 24 Mar 2000 20:07:17 GMT
Try the following basic JavaBean. It uses JavaMail API
and Java Activation Framework. You need to download both
and put the jars in your classpath. It does not provide
all the features like attachments, etc, but you can explore further.

Shahid.
====================== Bean =======================
package  javamail;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;

public class JMailBean {
  InternetAddress fromAddress, toAddress;
  Session session;
  MimeMessage msg;
  Properties prop;

  public JMailBean() {
    Properties prop = new Properties();
    prop.put("mail.smtp.host", "your.mail.server"); 
    session = Session.getDefaultInstance(prop,null);
    msg = new MimeMessage(session);
  }

  public void setFromAddress(String sender) {
    try { fromAddress = new InternetAddress(sender); }
    catch (AddressException e) { };
    try { msg.setFrom(fromAddress); }
    catch (MessagingException e) { };
  }

  public void setToAddress(String recepient) {
    try { toAddress = new InternetAddress(recepient); }
    catch (AddressException e) { };
    try { msg.setRecipient(Message.RecipientType.TO, toAddress); }
    catch (MessagingException e) { };
  }

  public void setSubject(String subject) {
    try { msg.setSubject(subject); }
    catch (MessagingException e) { };
  }

  public void setContent(String content) {
    try { msg.setContent(content, "text/plain"); }
    catch (MessagingException e) { };
  }

  public void sendMail() {
    try { Transport.send( msg ); }
    catch (MessagingException e) { };
  }
}
====================== End Bean ===================


 ---- you wrote: 
> Is there a facility or example somewhere for a webpage to email gateway,
> like the ones for CGI?  I have the CGI ones working, but would like to
> intergrate email into a web app I am writing with Servlets.
> 
> 
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org
> 


---------------------------------------------------
Get free personalized email at http://www.iname.com

Mime
View raw message