1-
21import java .io .File ;
32import java .io .FileInputStream ;
43import java .util .*;
@@ -19,15 +18,13 @@ public static void main(String[] args) {
1918 public void read () {
2019 Properties props = new Properties ();
2120
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 !" ;
3026
27+ try {
3128 Session session = Session .getDefaultInstance (props , null );
3229
3330 Store store = session .getStore ("imaps" );
@@ -39,29 +36,23 @@ public void read() {
3936 Message messages [] = inbox .search (new FlagTerm (new Flags (Flags .Flag .SEEN ), false ));
4037
4138 for (int i = 0 ; i < messages .length ; i ++) {
42-
4339 if (messages [i ].getFrom ()[0 ].toString ().contains (Kumar_mail )) {
44-
4540 String bodytext = null ;
4641 Object content = messages [i ].getContent ();
4742 if (content instanceof String ) {
4843 bodytext = (String ) content ;
49-
5044 } else if (content instanceof Multipart ) {
51-
5245 Multipart mp = (Multipart ) content ;
5346
5447 BodyPart bp = mp .getBodyPart (mp .getCount () - 1 );
5548 bodytext = (String ) bp .getContent ();
56-
5749 }
5850
5951 Pattern pattern = Pattern .compile ("sorry|help|wrong" , Pattern .CASE_INSENSITIVE );
6052 Matcher matcher = pattern .matcher (bodytext );
6153 // check all occurance
6254
6355 if (matcher .find ()) {
64-
6556 Properties props1 = new Properties ();
6657 Address [] tomail ;
6758
@@ -73,23 +64,18 @@ public void read() {
7364 msg .setSubject ("Database fixes" );
7465 msg .setText ("No problem. I've fixed it. \n \n Please be careful next time." );
7566 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+ }
8172 }
82-
8373
84- }
85- }
8674 inbox .close (true );
8775 store .close ();
8876
89- }catch (Exception e )
90- {
91-
77+ } catch (Exception e ) {
9278 e .printStackTrace ();
9379 }
9480 }
95- }
81+ }
0 commit comments