The following example is a very simple sendmail tool using 'mailto:'
protocol, you can write your own mail handler for smtp protocol or other
ultilizing net, io package .

import java.io.*;
import java.net.*;


/**
 * This program sends e-mail using a mailto: URL
 **/
public class SendMail {
    
    private String to, message;
    private String from, subject;
    final static String EmailServer = "company.com";
   
    private URL u;
    private URLConnection c;
    private PrintWriter out;
    
  public SendMail (String t, String m)
  {
   to = t;
   
   message = new String ("You mesage ");
   subject = new String ("Your subject");
   from = new String ("Sender name");
   
  }
  public int send(){
   int rtnStatus=0; 
   try {
    System.getProperties().put("mail.host", EmailServer);
    u = new URL("mailto:" + to);
    c = u.openConnection();
    c.setDoInput(false);
    c.setDoOutput(true);
    System.out.flush();
    c.connect();
    out = new PrintWriter(new OutputStreamWriter(c.getOutputStream()));
   
    out.println ("From: \""  + from + "\" <");             
    out.println ("To: " + to);
    out.println ("Subject: " + subject);
    out.println ();
   
    out.println (message);
   
    //out.close();
    //System.out.println("Message was sent");
    System.out.flush();
    rtnStatus = 1;  //if sucessful return 1 
   }catch (Exception e)
   {
    System.err.println(e);
   }finally {out.close();return rtnStatus;}
  }
}

> -----Original Message-----
> From: Matt Zagni [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, October 22, 1998 3:45 AM
> To:   [EMAIL PROTECTED]
> Subject:      request for a sendmail java script
> 
> 
> Hi,
> 
> Please could someone mail me an example of a sendmail java class file
> and .java file or even a url where examples are located.
> 
> Many thanks
> 
> Matt

Reply via email to