Javaduke original in www.dukejava.com homepage!
MailService.java// The source code is as follows: (debugging in www.mycgiserver.com)
Package javaduke.servlet;
Import javax.servlet. *;
Import javax.servlet.http. *;
Import java.io. *;
Import java.util. *;
Import javax.mail. *;
Import javax.mail.internet. *;
Public class mailservice extends httpservlet {
INT INDEX = 0;
String Err = NULL;
// Initialize Global Variables
Public void init (servletconfig config) throws servletexception {
Super.init (config);
}
// service the request
Public void service (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {
String soilto = null;
String messageText = "/ n or below is form";
Mailto = Request.getParameter ("email");
ENUMERATION Keys;
String Key, Value;
Keys = Request.getParameterNames ();
While (keys.hasmoreElements ()) {
Key = (string) keys.nextelement ();
Value = Request.getParameter (key);
MessageText = "/ N" Key ":" value;
}
MessageText = "/ n forward mail handler from /nwww.dukejava.com";
Properties Pros = new property ();
Pros.Put ("mail.smtp.host", "mycgiServer.com");
Session session = session.getDefaultInstance (PROS, NULL);
Try {
Message Message = New MimeMessage (session);
Message.setsubject ("Dukejava.com Welcome");
Message.SetFrom (New InternetAddress ")))))));" Send Xinxin @ dukejava.com ")
Internet ADRESS Address = New InternetAddress (Mailto);
Message.setRecipient (Message. RecipientType.to, Address);
Message.Settext (MessageText);
TRANSPORT.SEND (Message);
} catch (messagingException exa) {int index = 1; err = exa.tostring ();
IF (INDEX == 0) {
Response.setContentType (Text / HTML ");
PrintWriter out = new printwriter (response.getoutputStream ()); out.println ("");
Out.println ("
Out.println ("
Out.println ("
information successfully sent");
Out.println ("/ n
Out.println ("/ n
Out.println (" Body> HTML>");
Out.close ();
}
IF (INDEX == 1) {
Response.setContentType (Text / HTML ");
PrintWriter out = new printwriter (response.getoutputstream ());
Out.println ("");
Out.println ("
Out.println ("
Out.println ("
information transmission failed");
Out.println ("/ n
Error Cause:" ERR);
Out.println ("/ n
Out.println ("/ n
Out.println (" Body> HTML>");
Out.close ();
}
}
// Get Servlet Information
Public string getServletInfo () {
Return "Javaduke.mailService Information";
}
}