Boa noite pessoal.
Estou tentando desenvolver uma classe para envio de e-mail. Porém o mesmo esta retornando o seguinte erro.
Eu testei para servidores não autenticados e funcionou, mas para o gmail não, pois o mesmo é autenticado. MAs eu estou passando o usuário e a senha e mesmo assim dá esse erro
Alguem pode me ajudar ?
[b]530 5.7.0 Must issue a STARTTLS command first h19sm3080504wxd
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first h19sm3080504wxd
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at jm.javamail.JMEnvioAutenticado.main(JMEnvioAutenticado.java:25)
QUIT
221 2.0.0 mx.gmail.com closing connection h19sm3080504wxd
ERRO =530 5.7.0 Must issue a STARTTLS command first h19sm3080504wxd[/b]
abaixo está o código.
[code]import java.util.Properties;
import javax.mail.;
import javax.mail.internet.;
public class JMEnvioAutenticado {
public static void main(String[] args) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new JMAuthenticator());
session.setDebug(true);
Message msg = new MimeMessage(session);
try {
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress("mauricionunes_44@hotmail.com"));
msg.setFrom(new InternetAddress("nunes.mauricio@gmail.com"));
msg.setSubject("Teste da JavaMail GMAIL");
msg.setText("Ola, como vai Gmailç?");
// Envia mensagem.
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("ERRO ="+e.getMessage());
}
}
}[/code]
[code]package jm.javamail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.mail.*;
public class JMAuthenticator extends Authenticator {
public String username = null;
public String password = null;
/* public JMAuthenticator(String user, String pwd) {
username = user;
password = pwd;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}*/
public PasswordAuthentication getPasswordAuthentication(){
String usuario = null, senha = null;
// Lê informações de usuário e senha.
try {
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
System.out.println("Digite usuario: ");
usuario = in.readLine();
System.out.println("Digite senha: ");
senha = in.readLine();
}
catch (IOException e) {
System.out.println("ERRO Autenticação = "+e.getMessage());
}
// Cria PasswordAuthentication.
return new PasswordAuthentication(usuario, senha);
}
}[/code]