I'm having a problem sending an email from an application made in Java (netbeans). The problem is that I want to use a mail "webmail" instead of gmail (where it works) the issue is that by making the corresponding changes, the frame freezes and I can not do anything else, for quite some time. I share the code:
public void SendMail() {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "mail.smartsim.cl"); // modificar por smtp.gmail.com
props.put("mail.smtp.port", "465"); // puerto 587
//props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
//props.put("mail.smtp.starttls.enable", "true");
Session session;
session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(username, password);
//return new PasswordAuthentication(username, password);
}
});
try {
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setSubject("Recuperacion de Contraseña");
message.addRecipient(Message.RecipientType.TO,new InternetAddress("[email protected]"));
message.setText("Nombre Usuario: " +Usuario+" " +"Email de contacto: "+ Mensaje);
// Envia el mensaje
Transport.send(message);
JOptionPane.showMessageDialog(this, "Mensaje Enviado Correctamente");
} catch (MessagingException e) {
Logger.getLogger(Enviarcorreo.class.getName()).log(Level.SEVERE, null, e);
}
}