Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int linha = tbReserva.getSelectedRow();
- if(linha == -1){
- JOptionPane.showMessageDialog(rootPane, "Selecione uma linha!");
- }else if(JOptionPane.showConfirmDialog
- (rootPane, "O livro realmente está disponivel?", "Reivindicar"
- , JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
- try{
- String host ="smtp.gmail.com" ;
- String user = "oslibaryfvs@gmail.com";
- String pass = "codingway2018";
- String to = (String) tbReserva.getValueAt(linha, 2);
- String from = "nandoaraujo353@gmail.com";
- String subject = "OSLibary FVS";
- String messageText = "A biblioteca da FVS informa que o seu livro" +(String) tbReserva.getValueAt(linha, 3)+ "encontra-se disponível";
- boolean sessionDebug = false;
- Properties props = System.getProperties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.required", "true");
- java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
- Session mailSession = Session.getDefaultInstance(props, null);
- mailSession.setDebug(sessionDebug);
- Message msg = new MimeMessage(mailSession);
- msg.setFrom(new InternetAddress(from));
- InternetAddress[] address = {new InternetAddress(to)};
- msg.setRecipients(Message.RecipientType.TO, address);
- msg.setSubject(subject); msg.setSentDate(new Date());
- msg.setText(messageText);
- Transport transport=mailSession.getTransport("smtp");
- transport.connect(host, user, pass);
- transport.sendMessage(msg, msg.getAllRecipients());
- transport.close();
- System.out.println("message send successfully");
- }catch(Exception ex)
- {
- System.out.println(ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement