Subversion Repositories SmartDukaan

Rev

Rev 5131 | Rev 5181 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5128 amit.gupta 1
package in.shop2020.catalog.util;
2
 
3
import in.shop2020.utils.GmailUtils;
4
 
5
import java.io.ByteArrayOutputStream;
5140 amit.gupta 6
import java.io.FileNotFoundException;
7
import java.io.FileOutputStream;
8
import java.io.IOException;
5128 amit.gupta 9
import java.text.DateFormat;
10
import java.text.SimpleDateFormat;
11
import java.util.Date;
12
 
13
 
14
public class ReportSender implements Runnable {
15
	@Override
16
	public void run() {
17
		ReportGenerator repGen = new ReportGenerator();
18
		ByteArrayOutputStream baos = repGen.generateExcelStream(ReportGenerator.TYPE_BOTH);
19
		if(baos != null){
20
			GmailUtils gm = new GmailUtils();
21
			DateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd");
5140 amit.gupta 22
			String[] recepients = {"cnc.center@shop2020.in", "ashutosh.saxena@shop2020.in", "chaitnaya.vats@shop2020.in"};
5128 amit.gupta 23
			String subject = "Items that require your attention.";
24
			String from = "cnc.center@shop2020.in";
25
			String password = "5h0p2o2o";
26
			String fileName = "items."+ dateFormatter.format(new Date()) + ".xls";
5140 amit.gupta 27
			byte [] bytes = baos.toByteArray();
28
 
29
		     try
30
		     {
31
		      FileOutputStream fos = new FileOutputStream(fileName);
32
 
33
		      /*
34
		       * To write byte array to a file, use
35
		       * void write(byte[] bArray) method of Java FileOutputStream class.
36
		       *
37
		       * This method writes given byte array to a file.
38
		       */
39
 
40
		       fos.write(bytes);
41
 
42
		      /*
43
		       * Close FileOutputStream using,
44
		       * void close() method of Java FileOutputStream class.
45
		       *
46
		       */
47
 
48
		       fos.close();
49
 
50
		     }
51
		     catch(FileNotFoundException ex)
52
		     {
53
		      System.out.println("FileNotFoundException : " + ex);
54
		     }
55
		     catch(IOException ioe)
56
		     {
57
		      System.out.println("IOException : " + ioe);
58
		     }
59
 
5128 amit.gupta 60
			try {
5140 amit.gupta 61
				gm.sendSSLMessage(recepients, subject, "PFA", from, password, fileName);
5128 amit.gupta 62
			} catch (Exception e) {
63
				e.printStackTrace();
64
			}
65
		}
66
	}
67
}