Advertisement
Guest User

Untitled

a guest
Jun 10th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. int linha = tbReserva.getSelectedRow();
  2. if(linha == -1){
  3. JOptionPane.showMessageDialog(rootPane, "Selecione uma linha!");
  4. }else if(JOptionPane.showConfirmDialog
  5. (rootPane, "O livro realmente está disponivel?", "Reivindicar"
  6. , JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
  7. try{
  8. String host ="smtp.gmail.com" ;
  9. String user = "oslibaryfvs@gmail.com";
  10. String pass = "codingway2018";
  11. String to = (String) tbReserva.getValueAt(linha, 2);
  12. String from = "nandoaraujo353@gmail.com";
  13. String subject = "OSLibary FVS";
  14. String messageText = "A biblioteca da FVS informa que o seu livro" +(String) tbReserva.getValueAt(linha, 3)+ "encontra-se disponível";
  15. boolean sessionDebug = false;
  16.  
  17. Properties props = System.getProperties();
  18.  
  19. props.put("mail.smtp.starttls.enable", "true");
  20. props.put("mail.smtp.host", host);
  21. props.put("mail.smtp.port", "587");
  22. props.put("mail.smtp.auth", "true");
  23. props.put("mail.smtp.starttls.required", "true");
  24.  
  25. java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
  26. Session mailSession = Session.getDefaultInstance(props, null);
  27. mailSession.setDebug(sessionDebug);
  28. Message msg = new MimeMessage(mailSession);
  29. msg.setFrom(new InternetAddress(from));
  30. InternetAddress[] address = {new InternetAddress(to)};
  31. msg.setRecipients(Message.RecipientType.TO, address);
  32. msg.setSubject(subject); msg.setSentDate(new Date());
  33. msg.setText(messageText);
  34.  
  35. Transport transport=mailSession.getTransport("smtp");
  36. transport.connect(host, user, pass);
  37. transport.sendMessage(msg, msg.getAllRecipients());
  38. transport.close();
  39. System.out.println("message send successfully");
  40. }catch(Exception ex)
  41. {
  42. System.out.println(ex);
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement