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.
Create a URL object.
Set a URLConnection object.
Create an OutputStream object from the URL object.
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"); } }
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.