//Imports
import java.io.*; // contains UnsupportedEncodingException
import javax.mail.*;
import javax.mail.internet.*;
// Build the message. A StringBuffer is used for speed instead of '+'.
StringBuffer sb = new StringBuffer();
sb.append("The following toys are out of stock\n");
sb.append("1. Dwezzles\n");
sb.append("2. Pickets\n");
sb.append("3. Bogos\n");
sb.append("4. Frammusses\n");
/// Set up Properties and Session for the message
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "outmail.mydomain.com");
props.setProperty("mail.from", "[EMAIL PROTECTED]");
Session sess = Session.getDefaultInstance(props, null); // This is javax.mail.Session. Authentication is usually not needed.
// Create the message
Message msg = new MimeMessage(sess);
InternetAddress[] addrs = new InternetAddress[1];
try
{
addrs[0] = new InternetAddress("[EMAIL PROTECTED]", "Chris Cringle");
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, addrs);
msg.setSubject("It's another Elf-It!!!");
msg.setSentDate(new Date());
msg.setContent(sb.toString(), "text/plain");
sess.getTransport(addrs[0]).send(msg);
/* For multiple recipients, this could also be:
Transport trans = sess.getTransport();
trans.send(msg, addrs);
But you would also need to catch SendFailedException...
*/
}
catch(UnsupportedEncodingException e1) { }
catch(NoSuchProviderException e2) { }
catch(MessagingException e3) { }
-----Original Message-----
From: Giscard Girard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 24, 1999 4:15 PM
To: [EMAIL PROTECTED]
Subject: mailing example?
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.
Thanks,
Giscard Girard
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
___________________________________________________________________________
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
