package com.mjm.solarInsertDB;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by user on 2017/4/10.
 */
public class test {

    public static void main(String[] args) {

        System.out.println("start");
        new test().doSendMail();


    }

    public void doSendMail() {

//        System.out.println("1");
//        Properties props = new Properties();
//        props.put("mail.smtp.host", "smtp.gmail.com");
//        props.put("mail.smtp.auth", "true");
//        props.put("mail.smtp.starttls.enable", "true");
//        props.put("mail.smtp.port", 587);
//        props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
//        Session session = Session.getInstance(props, new Authenticator() {
//            protected PasswordAuthentication getPasswordAuthentication() {
//                return new PasswordAuthentication("ivsserver01@gmail.com", "ficgreen2017");
//            }
//        });
//        System.out.println("2");
//        try {
//            Message msg = new MimeMessage(session);
//
//            msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getSendMailList()));
//            msg.setSubject("FIC Niagara Mail Test");
//            System.out.println("3");
//            //設定本文區的內容
//            MimeBodyPart mbp1 = new MimeBodyPart();
//            String s = "Dear Sir,\n\nPlease follow the report in the attachment, thanks!\n\nThis message is automatically sent, please do not reply directly!";
//
//            mbp1.setContent(s, "text/plain;charset=big5");
//            //設定附加檔
//            MimeBodyPart mbp2 = new MimeBodyPart();
//            FileDataSource fds = new FileDataSource("C:/ProgramData/Niagara4.2/vykon/shared/0071801/2017-04-17 inverter.csv");
//            mbp2.setDataHandler(new DataHandler(fds));
//            mbp2.setFileName("report.csv"); //附加檔在mail接收時，出現的檔案名稱
//            Multipart mp = new MimeMultipart();//把所有MimeBodyPart加進Multipart，所以如果有第二個附加檔，應該要有另一MultiBodyPart
//            mp.addBodyPart(mbp1);
//
//            msg.setContent(mp);
//            System.out.println("4");
//            Transport.send(msg);
//            System.out.println("send mail success!");
//            System.out.println("5");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//

    }

    private String getSendMailList() {
        String list = "jeremy_chang@fic.com.tw";


        return list;


    }

    private void run() {

        Calendar cal = Calendar.getInstance();//使用預設時區和語言環境獲得一個日曆。
        cal.add(Calendar.DAY_OF_MONTH, -90);//取當前日期的前一天.

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        System.out.println("Today is:" + format.format(cal.getTime()));

        String before90 = format.format(cal.getTime()) + " 00:00:00";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));


        try {
            Date sDate = sdf.parse(before90);

            System.out.println(sDate.getTime() / 1000);

        } catch (Exception e) {
            e.printStackTrace();
        }


        File a = new File("C:\\ProgramData\\Niagara4.2\\vykon\\shared\\0071801");

        String fullpath = a.getAbsolutePath();

        if (a.isDirectory()) {
            String[] filenames = a.list();
            for (int i = 0; i < filenames.length; i++) {
                File tempFile = new File(fullpath + "\\" + filenames[i]);
                if (tempFile.isDirectory()) {
                    System.out.println("目錄:" + filenames[i]);
                } else {
                    System.out.println("檔案:" + filenames[i]);


                }
            }
        } else {
            System.out.println("[" + a + "]不是目錄");
        }

    }


}
