Now from within Eclipse IDE start a new project from File > New > Project and then select Tomcat project (considering that the Tomcat-Eclipse plug-in is installed). Name the project as 'JavaMail.' As we intend to deploy our app on a hosting service provider's server, we will have to pack the JavaMail APIs into the WAR file so that during deployment the programs could get reference to the JavaMail libraries. For this reason copy the mail.jar and activation.jar files into the WEB-INF/lib folder. Also add these two jar files into the project's classpath. Once this initial configuration of the project 'JavaMail' has been completed we can now start building our Web app.
Designing the form and its Servlet The feedback form for the demo app is simple with two input fields for taking sender's e-mail address and his name, while the text area will be used for taking the user's feedback/comment. Name the fields appropriately so that their values can be retrieved by the Servlet while sending the mail. On the form's action attribute set the mapped path that will call for the Servlet. Now let's start coding for the Servlet that will retrieve the values from the feedback form and will send them across to an email account
For the demo app we are using Google Mail as the mail server to send mails. To send mails via Gmail, the SMTP mail protocol is used and the port for that on Gmail server is 465 and the host is smtp.gmail.com. The email account we refer here as 'demoaccount' is just for reference. Also Google only allows messages to be sent over SSL, so we will have to enable it. Also we have to login into the Gmail account and after authentication only the mail could be sent, so for this we will use Authentication also and set the property for that as true. Once the message is sent the transporter waits for a QUIT command, we can close the connection immediately by setting the quitwait property as false. Now with initial properties configured, we can proceed by sending the message. Let's look at the demo Servlet first then we will discuss some of the parameters used in that.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.