I am using jsp, servlet and classes in java to send an email from a form, it works on the PC locally using payara 4.1 and netbeans from one gmail to another but when I upload the application to a java host do not send in the mail I have the application on the host
www.blancopropiedades.cl/pruebaJavaMail /
Servlet:
Email email = new Email();
boolean resultado = email.enviarCorreo(mensaje, asunto);
class in java:
public class Email {
public boolean enviarCorreo(String mensaje, String asunto){
boolean enviado = false;
try{
String de = "[email protected]"; String clave =
"contraseña";
String para="[email protected]";
String host = "smtp.gmail.com";
Properties prop = System.getProperties();
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.smtp.host", host);
prop.put("mail.smtp.user",de);
prop.put("mail.smtp.password", clave);
prop.put("mail.smtp.port",587);
prop.put("mail.smtp.auth","true");
Session sesion = Session.getDefaultInstance(prop,null);
MimeMessage message = new MimeMessage(sesion);
message.setFrom(new InternetAddress(de));
message.setRecipient(Message.RecipientType.TO, new
InternetAddress(para));
message.setSubject(asunto);
message.setText(mensaje);
Transport transport = sesion.getTransport("smtp");
transport.connect(host,de,clave);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
enviado = true;
}catch(Exception e){
e.printStackTrace();
}
return enviado;
}