Use the mailto:URL class to mail a document

Mailing a document is a good example of using the URL class. Before you start, your client must connect to a mail server, so that the machine referenced by System Properties ( in this case salsa.sybase.com) is running a mail server, such as sendmail.

  1. Create a URL object.

  2. Set a URLConnection object.

  3. Create an OutputStream object from the URL object.

  4. Write the mail. For example:

    import java.io.*;
    import java.net.*;
    public class MailTo {
    
    			public static void sendIt() throws Exception{
    					System.getProperty("mail.host", "salsa.sybase.com");
    					URL url = new URL(mailto:"name@sybase.com");
     				URLConnection conn = url.openConnection();
     				PrintStream out = new PrintStream(conn.getOutputStream(), true); 
    				out.print ("From: kennys@sybase.com"+"\r\n");
    				out.print ("Subject: Works Great!"+"\r\n");
    				out.print ("Thanks for the example - it works  great!"+"\r\n");
    				out.close();
    				System.out.printIn("Messsage Sent");
    		}
    }
    
  5. Install mailto:URL for sending e-mail from within the database:

    select MailTo.sendIt()
    
    Message Sent!
    

A connection to a server is required for these actions.