Using the MailTo class URL to mail a document

Mailing a document is a good example of using the URL class. Before you start, you must have your client connected to a mailer, 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:

    public static void sendIt() throws Execption{
    System.getProperty("", "");
    URL url = new URL(mailto:"");
     URLConnection conn = url.openConnection();
     PrintStream out = new
      PrintStream(conn.getOutputStream(), true); 
    out.print ("From:"+"\r\n");
    out.print ("Subject: Works Great!"+"\r\n");
    out.print ("Thanks for the example - it works   great!"+"\r\n");
    System.out.printIn(“Messsage Sent”);
  5. Install the MailTo class for sending e-mail from within the database:

    select MailTo.sendIt()
    Message Sent!

A connection to a server is required for these actions.