Encontré la solución, para correos que usan stmps(seguro) y smtp normal, el smtps de google ocupa el puerto 465 que se ha mencionado anteriormente en este foro, les dejo el codigo para funcionar con google, si desean cambiar a otro servidor de correo con smtp normarl que usa el puerto 25 solo deben modificar la linea :
boolean ssl = true;
y ponerla como
boolean ssl = false;
y obviamente el nombre de usuario y contraseña
si tienen bien instaladas las librerias javamail y una salida a internet sin los puertos 25 y 465 bloquedos, seguro que funciona
Código PHP:
String to = mail; // to address
String from = "[email protected]"; // fromaddress
String subject = "Titulo del correo";
String message = "<b>Mensaje de prueba</b><br><h1>Hola></h1>";
String mailhost = "smtp.gmail.com"; // servidor smtp de gmail(smtps), pero en esta linea no lleva la "s" de "smtps"
String user = "[email protected]"; // Aqui va tu nombre de usuario, observa que va tambien "@gmail.com" no solamente el nombre de usuario
String password = "xxxx"; // Aqui va tu password
// in the case of an exception, print a message to the output log
boolean auth = true;
boolean ssl = true;
Properties props = System.getProperties();
if (mailhost != null){
props.put("mail.smtp.host", mailhost);
props.put("mail.smtps.host", mailhost);
}
if (auth){
props.put("mail.smtp.auth", "true");
props.put("mail.smtps.auth", "true");
}
props.put("mail.smtp.port", "25");
props.put("mail.smtps.port", "465");
// Get a Session object
javax.mail.Session session = javax.mail.Session.getInstance(props);
session.setDebug(true);
// construct the message
javax.mail.Message msg = new MimeMessage(session);
try {
// Set message details
msg.setFrom(new InternetAddress(from));
msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(message, "text/html");
//msg.setText(message);
// send the thing off
SMTPTransport t =
(SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp"); //si ssl=true, smtps si no smtp
try {
if (auth)
t.connect(mailhost, user, password);
else
t.connect();
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
log("Mail was sent successfully.");
} catch (Exception e) {
if (e instanceof SendFailedException) {
MessagingException sfe = (MessagingException)e;
if (sfe instanceof SMTPSendFailedException) {
SMTPSendFailedException ssfe =
(SMTPSendFailedException)sfe;
log("SMTP SEND FAILED:");
}
Exception ne;
while ((ne = sfe.getNextException()) != null &&
ne instanceof MessagingException) {
sfe = (MessagingException)ne;
if (sfe instanceof SMTPAddressFailedException) {
SMTPAddressFailedException ssfe =
(SMTPAddressFailedException)sfe;
log("ADDRESS FAILED:");
log(ssfe.toString());
log(" Address: " + ssfe.getAddress());
log(" Command: " + ssfe.getCommand());
log(" RetCode: " + ssfe.getReturnCode());
log(" Response: " + ssfe.getMessage());
} else if (sfe instanceof SMTPAddressSucceededException) {
log("ADDRESS SUCCEEDED:");
SMTPAddressSucceededException ssfe =
(SMTPAddressSucceededException)sfe;
}
}
} else {
log("Got Exception : " + e);
}
}
Ami me funcionó a la perfección, espero que les funcione.