1
-
2
1
import java .io .File ;
3
2
import java .io .FileInputStream ;
4
3
import java .util .*;
@@ -19,15 +18,13 @@ public static void main(String[] args) {
19
18
public void read () {
20
19
Properties props = new Properties ();
21
20
22
-
23
- //modify below properties to your details
24
- String host = "smtp.gmail.com" ;
25
- String username =
"[email protected] goes here" ;
26
- String password = "your password goes here " ;
27
- String Kumar_mail = "the mail address to be replied to !" ;
28
-
29
- try {
21
+ //modify below properties to your details
22
+ String host = "smtp.gmail.com" ;
23
+ String username =
"[email protected] goes here" ;
24
+ String password = "your password goes here " ;
25
+ String Kumar_mail = "the mail address to be replied to !" ;
30
26
27
+ try {
31
28
Session session = Session .getDefaultInstance (props , null );
32
29
33
30
Store store = session .getStore ("imaps" );
@@ -39,29 +36,23 @@ public void read() {
39
36
Message messages [] = inbox .search (new FlagTerm (new Flags (Flags .Flag .SEEN ), false ));
40
37
41
38
for (int i = 0 ; i < messages .length ; i ++) {
42
-
43
39
if (messages [i ].getFrom ()[0 ].toString ().contains (Kumar_mail )) {
44
-
45
40
String bodytext = null ;
46
41
Object content = messages [i ].getContent ();
47
42
if (content instanceof String ) {
48
43
bodytext = (String ) content ;
49
-
50
44
} else if (content instanceof Multipart ) {
51
-
52
45
Multipart mp = (Multipart ) content ;
53
46
54
47
BodyPart bp = mp .getBodyPart (mp .getCount () - 1 );
55
48
bodytext = (String ) bp .getContent ();
56
-
57
49
}
58
50
59
51
Pattern pattern = Pattern .compile ("sorry|help|wrong" , Pattern .CASE_INSENSITIVE );
60
52
Matcher matcher = pattern .matcher (bodytext );
61
53
// check all occurance
62
54
63
55
if (matcher .find ()) {
64
-
65
56
Properties props1 = new Properties ();
66
57
Address [] tomail ;
67
58
@@ -73,23 +64,18 @@ public void read() {
73
64
msg .setSubject ("Database fixes" );
74
65
msg .setText ("No problem. I've fixed it. \n \n Please be careful next time." );
75
66
Transport t = null ;
76
- t = session .getTransport ("smtps" );
77
- t .connect (host , username , password );
78
- t .sendMessage (msg , msg .getAllRecipients ());
79
-
80
-
67
+ t = session .getTransport ("smtps" );
68
+ t .connect (host , username , password );
69
+ t .sendMessage (msg , msg .getAllRecipients ());
70
+ }
71
+ }
81
72
}
82
-
83
73
84
- }
85
- }
86
74
inbox .close (true );
87
75
store .close ();
88
76
89
- }catch (Exception e )
90
- {
91
-
77
+ } catch (Exception e ) {
92
78
e .printStackTrace ();
93
79
}
94
80
}
95
- }
81
+ }
0 commit comments