public void enviarMensaje (){ Properties props = new Properties();
props.put("mail.smtp.auth","true"); props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host","smtp.gmail.com"); props.put("mail.smtp.port","587"); Session
session = Session.getInstance(props, new javax.mail.Authenticator() { protected
PasswordAuthentication getPasswordAuthentication(){ return new
PasswordAuthentication(Username,PassWord); } }); try { To = txtCorreo.getText(); Message
message = new MimeMessage (session); message.setFrom(new InternetAddress(Username));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(To));
message.setText(Mensaje +"Usuario: " + Usuario +" - Contrasea: "+ Contrasea);
message.setSubject(Subject); Transport.send(message);
JOptionPane.showMessageDialog(this,"Su mensaje ha sido enviado");
} catch (MessagingException e) { throw new RuntimeException(e); } }
public static String Username = "[email protected]"; public static String PassWord
= "anghidiaz"; String Mensaje = ""; String To ; String Subject = "Datos de nuevo Usuario"; String
Usuario = " "; String Contrasea = " ";
private String generarUsuario (){ String code=" "; String nombre[] = txtNombre.getText().split(" ");
for(String palabra:nombre){ code =
""+palabra.charAt(0)+""+palabra.charAt(1)+""+txtcode.getText(); } return code; }
private String generarContrasea (){
String NUMEROS = "0123456789";
String MAYUSCULAS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String MINUSCULAS = "abcdefghijklmnopqrstuvwxyz";
String key = NUMEROS +MAYUSCULAS+MINUSCULAS;
String pswd = "";
for (int i = 0; i < 6; i++)
{ pswd+=(key.charAt((int)(Math.random() * key.length()))); }
return pswd; }