On Tue, Mar 16, 1999 at 12:25:20AM -0800, Danny Rubis wrote:
> I am trying to send E-mail from a servlet. 'sun.net.smtp.SmtpClient' is
> in the JDK classes.zip but I can't find any docs on it. I searched Sun
Here is a simple example (replace "mail" with your SMTP relay):
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
sun.net.smtp.SmtpClient sc = new sun.net.smtp.SmtpClient("mail");
sc.from("[EMAIL PROTECTED]"); //Note: quite picky about the format
sc.to("[EMAIL PROTECTED]");
PrintStream ps = sc.startMessage();
ps.println("From: Me <[EMAIL PROTECTED]>");
ps.println("To: Someone <[EMAIL PROTECTED]>");
ps.println("Subject: Testing 123");
ps.println();
ps.println("This is the message body.");
ps.println("Blah blah blah");
sc.closeServer();
}
}
This may or may not work, depending on your mail server software. I get
syntax errors from some SMTP servers and it works ok with others.
Why not use JavaMail instead, it's more standard and more likely to
work in other environments?
___________________________________________________________________________
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