The links for JavaMail
http://java.sun.com/products/javamail/index.html  to get JavaMail.  There
is also a link on that page for the pop3 provider.  You also need
http://java.sun.com/beans/glasgow/jaf.html  which is the Java
Activation Framework(JAF).  All 3 jars are small an you really only
need JavaMail and JAF to send mail.  It really is a bit more complex
but not so bad once you start using it.  A modified version of the
sample that helped me is below.

import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

class SimpleJavaMail
{
   public static void main (String args []) throws MessagingException
 {
     new SimpleJavaMail();
   }
   public SimpleJavaMail() throws MessagingException
   {
    Properties props = new Properties();
    props.put("mail.smtp.host","yourserver.com");
    InternetAddress[] addrs=null;
    Session session = Session.getDefaultInstance(props,null);
          String msgContent = new String();
    try
    {
     msgContent = "The message\nOn a second line"
     Message msg = new MimeMessage(session);
     msg.setHeader("X-Mailer", "JavaMail");
            msg.setSentDate(new Date());
     InternetAddress from = new InternetAddress("[EMAIL PROTECTED]");
            InternetAddress rcp1 = new InternetAddress("[EMAIL PROTECTED]");
     InternetAddress rcp2 = new InternetAddress("[EMAIL PROTECTED]");
     msg.setFrom(from);

     InternetAddress[] address = { rcp1, rcp2 };
            msg.setRecipients(Message.RecipientType.TO,address);
     msg.setSubject("JavaMail anyone?");
     msg.setContent(msgContent,"text/plain");
           msg.setSentDate(new Date());
     Transport.send(msg);
    }
    catch (Exception ex)
    {
     ex.printStackTrace();
    }
   }

}



Giscard Girard wrote:

>Hi all,  I'm looking for an example on how to mail from a servlet, i
>downloaded the JavaMail API, but i'd like to see an example somewhere to
>help me out.  Right now i'm mailing out with an ASP activex control, but
>i'm going to be posting to a servlet so i'd like to send the mail from
>the servlet.
>
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to