-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfxmail.java
More file actions
134 lines (98 loc) · 4.38 KB
/
fxmail.java
File metadata and controls
134 lines (98 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package mail;
import bloodbanks.Main;
import java.util.Properties;
import javafx.util.Duration;
import javax.swing.JOptionPane;
import tray.notification.NotificationType;
import tray.notification.TrayNotification;
import com.sun.mail.smtp.SMTPTransport;
import java.util.Properties;
import javafx.application.Platform;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import tray.animations.AnimationType;
public class fxmail {
private String to = "MAIL DESTINATION";
private String from = "MAIL SOURCE";
private Properties props;
private Session xss;
private String pass = "YOUR PASSWORD HERE OF THE MAIL SOURCE";
private NotificationType n;
private String title;
private String message;
public fxmail(){
this.props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
this.xss = Session.getDefaultInstance(this.props, new Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from,pass);
}
});
}
public void execute(boolean xcase){
boolean flag = false;
new Thread(new Runnable(){
@Override
public void run() {
boolean f = xcase;
boolean res = sendMail(f);
Platform.runLater(new Runnable(){
@Override
public void run() {
if(res){
displayNotify(true);
}
else{
displayNotify(false);
}
}
});
}
}).start();
}
private boolean sendMail(boolean xcase){
boolean flag = false;
try{
MimeMessage msg = new MimeMessage(this.xss);
msg.setFrom(new InternetAddress(this.from));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(this.to));
msg.setSubject("Sistema Gestor de Bancos de Sangre (S.G.B.S) Jesús José Navarrete Baca");
if(xcase){
msg.setText("***Inicio de Sesion Exitoso***\n"+ "Aviso: "+Main.usuario.nombre + " " +Main.usuario.apellido + " ha iniciado Sesion Satisfactoriamente en el Sistema.");
}
else{
msg.setText("***Intento de Inicio de Sesion Fallido***\n Aviso: Intruso ha intentado acceder al sistema de informacion.");
}
Transport.send(msg);
flag = true;
}
catch(MessagingException ex){
System.out.println(ex.getMessage());
}
return flag;
}
private void displayNotify(boolean flag){
this.title = "Notificación de Inicio de Sesión";
if(!flag){
n = NotificationType.WARNING;
this.message = "Ha ocurrido un Error al Enviar Correo de Notificacion.";
}
else{
n = NotificationType.SUCCESS;
this.message = "Mensaje de Notificacion Enviado a Correo(s) Notificable(s)";
}
TrayNotification tray = new TrayNotification();
tray.setTitle(title);
tray.setMessage(this.message);
tray.setAnimationType(AnimationType.SLIDE);
tray.setNotificationType(n);
tray.showAndDismiss(Duration.seconds(15));
}
}