Sending Email: Browser Version


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


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


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 Mailto URL&cc=dilbert@office.comics">contact 

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);

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 ...

Get Java Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.