Olá, gostaria de saber porque não funciona esse código:
######### Em JSP
<%
1 Properties props = new Properties();
2
3 props.put(“mail.smtp.host”, “<a href="http://smtp.gmail.com">smtp.gmail.com</a>”);
4 props.put(“mail.smtp.auth”, “true”);
5
6
7 Session s = Session.getDefaultInstance(props, new Autenticar(“emailalguem@gmail”, “$$$$$”));
8
9 MimeMessage message = new MimeMessage(s);
10
11 InternetAddress from = new InternetAddress(“emailalguem@gmai”);
12 message.setFrom(from);
13 InternetAddress to = new InternetAddress(“[email removido]”);
14 message.addRecipient(Message.RecipientType.TO, to);
15 message.setSubject(“Teste usando JavaMail.”);
16 message.setText(“Seja bem vindo JavaMail”);
17
18 Transport.send(message);
%>
############Erro na JSP
org.apache.jasper.JasperException: An exception occurred processing JSP page /enviandoEmail.jsp at line 18
javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: 465, port: 25;
javax.mail.MessagingException: Could not connect to SMTP host: 465, port: 25;
############# Classe de autenticação:
public class Autenticar extends Authenticator{
private String usuario;
private String senha;
public Autenticar(){
}
public Autenticar(String usuario, String senha){
this.usuario = usuario;
this.senha = senha;
}
public PasswordAuthentication getPasswordAuthentication(){
PasswordAuthentication obj = new PasswordAuthentication(usuario, senha);
String senha = obj.getPassword();
String login = obj.getUserName();
return new PasswordAuthentication(usuario, senha);
}
}