Pessoal, estou tentando implementar uma classe que dispara um email automaticamente. Estou tentando implementar essa classe no meu serviço e aqui tem um servidor de email proprio. Já li muitos artigos e muitos Posts no forum, mas não consegui resolver meu problema. Portanto se alguem souber como me ajudar fico grato. Seguem o codigo e o erro no console respectivamente.
//Codigo
import java.util.Properties;
import javax.mail.<em>;
import javax.mail.internet.</em>;
public class Enviar {
private String remetente;
private String destinatario;
private String smtpHost;
private String porta;
private String assunto;
private Properties propriedades;
private Session sessao;
private static String usuario;
private static String senha;
private static class Autenticacao extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(usuario, senha);
}
}
public Enviar(String remetente, String destinatario, String assunto,String smtpHost, String porta, String usuario, String senha)
{
this.remetente = remetente;
this.destinatario = destinatario;
this.assunto = assunto;
this.smtpHost = smtpHost;
this.porta = porta;
this.usuario = usuario;
this.senha = senha;
this.propriedades = System.getProperties();
this.propriedades.put("mail.smtp.host", this.smtpHost);
this.propriedades.put("mail.smtp.auth", "false");
this.propriedades.put("mail.debug", "true");
this.propriedades.put("mail.smtp.debug", "true");
this.propriedades.put("mail.smtp.port", this.porta);
this.propriedades.put("mail.smtp.starttls.enable", "true");
this.propriedades.put("mail.smtp.socketFactory.port", this.porta);
this.propriedades.put("mail.smtp.socketFactory.fallback", "true");
//this.propriedades.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
//Authenticator auth = new Autenticacao();
this.sessao = Session.getDefaultInstance(this.propriedades,null);// auth);
try {
Message mensagem = new MimeMessage(this.sessao);
mensagem.setSubject(this.assunto);
mensagem.setFrom(new InternetAddress(this.remetente));
mensagem.addRecipient(Message.RecipientType.TO,
new InternetAddress(this.destinatario));
mensagem.setText("Este é o corpo da mensagem");
System.out.println("Enviando mensagem");
Transport.send(mensagem);
System.out.println("Mensagem enviada");
} catch (Exception err) {
System.out.println("Erro ao enviar mensagem");
}
}
public static void main(String args[]) {
String remetente = "[email removido]";
String destinatario = "[email removido]";
String assunto = "Teste de Envio";
String smtpHost = "mail.xxx.xx";
String porta = "110";
String usuario = "[email removido]";
String senha = "xxxxx";
new Enviar(remetente, destinatario, assunto, smtpHost, porta, usuario, senha);
}
}
//Erro
[color=red]Enviando mensagem
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host “mail.xxx.xxx”, port 110, isSSL false
+OK Hello there.
DEBUG SMTP: bad server response: +OK Hello there.
DEBUG SMTP: could not connect to host “mail.xxx.xxx”, port: 110, response: -1
Erro ao enviar mensagem[/color]