} catch (MessagingException mex) { mex.printStackTrace(); System.out.println("Mail not sent");} } //service ends here}
For the above code mention the init() and destroy() method also. Then in the Properties we have set all the parameters for forwarding the mail. The MimeMessage initiates the session that will use the Properties parameters and set the values from the feedback form and configure the message body. The Transport will send the message over the set protocol, in our case SMTP. As we use Authenticator class named as SMTPAuthenticator for password verification, let's define the same.
class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( "demoaccount", "password");
}
This way we can use JavaMail to send the feedback of a user as e-mail message to a Gmail account. Even when the web hosting provider does not facilitate you with a mail server you have JavaMail and Gmail to implement the mailing system for Web app.
In Conclusion JavaMail API provides facility with which a developer can configure a complete mail system for sending/receiving mails over standard mail protocols. It's a great way to enhance your Web applications.
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.