Autenticação

1 resposta
M

Olá…

O meu servidor smtp quer autenticação para enviar e-mail. Gostaria de saber como faço pra trabalhar com a classe Authenticator do pacote javaMail.
No tutorial ele mostra:

Properties props = new Properties();

// fill props with any information

Authenticator auth = new MyAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

mas eu tenho que setar mais alguma coisa?

1 Resposta

ricardolecheta

da uma olhada:

Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth", "true");

mailSession = Session.getInstance(props, new MailAuthenticator(username, password));
transport = mailSession.getTransport("smtp");
public class MailAuthenticator extends Authenticator
{
	private String username = null;
	private String password = null;

	public MailAuthenticator(String username, String password)
	{
		this.username = username;
		this.password = password;
	}

	protected PasswordAuthentication getPasswordAuthentication()
	{
		return new PasswordAuthentication(username, password);
	}
}
Criado 1 de dezembro de 2003
Ultima resposta 1 de dez. de 2003
Respostas 1
Participantes 2