i have all .jar files installed at correct position...and getting ""
package jmail;
import java.util.Properties;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class mail implements ActionListener
{
public void processAction(ActionEvent event) throws AbortProcessingException
{
final
String username = "vkg.ssdn@gmail.com";
final String password = "password";
Properties prop = new Properties();
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "587");
FacesContext cont = FacesContext.getCurrentInstance();
HttpServletResponse resp=(HttpServletResponse)cont.getExternalContext().getResponse();
HttpSession ses=(HttpSession)cont.getExternalContext().getSession(true);
Session session = Session.getDefaultInstance(prop,
new javax.mail.Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(username,password);} });
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(("vkg.ssdn@gmail.com")));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("vkg.ssdn@gmail.com"));
message.setSubject("Testing Subject");
message.setText("hello friends this is great job....,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("done");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}