O'Reilly logo

Java Cookbook by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending Email: Browser Version

Problem

You want an applet to permit the user to compose and send email.

Solution

Use a mailto: URL, but hide it in some Java code.

Discussion

Since most web browsers are now configured with either built-in or linked-in email clients, you can use the mailto: URL as a poor-person’s email composer to have users contact you. Many people prefer this to a fill-in-the-blank “mail” form connected to a CGI script or servlet (see Chapter 18), since they can use a specialized tool and save their own copy of the mail either in their log file or by CC’ing their own account. While you could use a mailto: URL directly in HTML, experience suggests that a species of parasite called a SPAM perpetrator will attach itself permanently to your mailbox if you do. Permanently, but not symbiotically, since this alleged life-form offers nothing in return to its host.

<H1>Test</H1> <P>Here is how to <A HREF="mailto:spam
-magnet@darwinsys.com?subject=Testing Mailto URL&cc=dilbert@office.comics">contact 
us</A>

My approach is to hide the mailto: URL inside a Java applet, where SPAM perps are less likely to notice it. The applet uses showDocument( ) to activate the mailto: URL.

String theURL = "mailto:" + username;
URL targetURL = new URL(theURL);
getAppletContext.showDocument(targetURL);

Further, I break the email address into two parts and provide the @ directly, so it won’t be seen even if the SPAM-spider is clever enough to look into the PARAM parts of the APPLET tag. Since I ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required