I was trying to send a mail from my JSP page. I had tried every way to make that code work. Later I found that I have to set Mail Authentication, which lead me to solution.
Here is my SendMail cass, which you can implement in any Java application to send mail.
I have used a new Thread to send the mail, unless you do this the Thread which the mail sender was called will wait until the mail is sent due to this reason the whole program might halt for awhile