Ahora si tengo problemas de autentificacion, maldicion!!! haaaaaaaaaaaaaaa, tengo MyEclipse + JavaMail 1.4, y me tira este error:
14:51:39,406 INFO [STDOUT] com.sun.mail.smtp.SMTPSendFailedException: 530 5.5.1 Authentication Required 24sm3535897wrl
El codigo del programa es este:
Código PHP:
public void sendMail(String to) throws MessagingException{
String from = "[email protected]";
String subject = "Titulo del correo";
String message = "<b>Mensaje de prueba</b><br><h1>Hola></h1>";
String mailhost = "smtp.gmail.com";
String user = "[email protected]";
String password = "pass";
boolean auth = true;
boolean ssl = true;
boolean STARTTLS = 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", auth);
props.put("mail.smtps.auth", auth);
}
props.put("mail.smtp.port", "25");
props.put("mail.smtps.port", "465");
props.put("mail.smtps.STARTTLS.enable", STARTTLS);
// 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);
msg.saveChanges();
// send the thing off
//SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
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();
}
} catch (Exception e) {
if (e instanceof SendFailedException) {
MessagingException sfe = (MessagingException)e;
Exception ne;
while ((ne = sfe.getNextException()) != null &&
ne instanceof MessagingException){
sfe = (MessagingException)ne;
}
}
e.printStackTrace();
}
}
Por favor ayudenmen!!