OSDN Git Service

2019-02-11
[hayashilib/hayashi.git] / src / hayashi / yuu / tools / mail / SiteData.java
1 package hayashi.yuu.tools.mail;\r
2 \r
3 import hayashi.yuu.tools.properties.Properties;\r
4 import java.io.FileInputStream;\r
5 \r
6 /**\r
7  * メールアカウント設定情報を保持するインスタンス\r
8  * @author hayashi\r
9  * @version     2010/02/05      項目'MAIL_SMTP_PORT'を追加\r
10  */\r
11 public class SiteData {\r
12     public String MAIL_SMTP = "192.168.0.10";\r
13     public String MAIL_SMTP_PORT = "25";\r
14     public String MAIL_FROM = "webserver@xxx.co.jp";\r
15     public String MAIL_TO = "";\r
16     public String MAIL_CC = "";\r
17     public String MAIL_BCC = "";\r
18 \r
19     /**\r
20      * 'POP before SMTP'認証を行うかどうか\r
21      */\r
22     public boolean POP_before_SMTP = false;\r
23 \r
24     /**\r
25      * 'USER_AUTH'認証を行うかどうか\r
26      */\r
27     public boolean USER_AUTH = false;\r
28 \r
29     /**\r
30      * 'STARTTLS'認証を行うかどうか\r
31      */\r
32     public boolean STARTTLS = false;\r
33 \r
34     /**\r
35      * POPサーバー名('POP before SMTP'認証時のみ)\r
36      */\r
37     public String MAIL_POP = "";\r
38 \r
39     /**\r
40      * POPアカウント('POP before SMTP'認証時のみ)\r
41      */\r
42     public String USER_ID = "";\r
43 \r
44     /**\r
45      * POPアカウントのパスワード('POP before SMTP'認証時のみ)\r
46      */\r
47     public String PASSWORD = "";\r
48 \r
49     /**\r
50      * 指定されたプロパティファイルに定義された値でインスタンスを生成する。\r
51      * @param propertyFile      設定値を定義したプロパティファイルのパス名\r
52      */\r
53     public SiteData(String propertyFile) {\r
54         try {\r
55             Properties properties = new Properties();\r
56             properties.setPasswordItem("MAIL_PASSWORD");\r
57             properties.load(new FileInputStream(propertyFile));\r
58             setup(properties);\r
59         }\r
60         catch(Exception e) {\r
61             System.out.println(e);\r
62         }\r
63     }\r
64 \r
65     /**\r
66      * 指定されたプロパティファイルに定義された値でインスタンスを生成する。\r
67      * @param properties        設定値を定義したプロパティファイル\r
68      */\r
69     public SiteData(Properties properties) {\r
70         setup(properties);\r
71     }\r
72 \r
73     public void setup(java.util.Properties properties) {\r
74         String str = "";\r
75         if ((str = properties.getProperty("mail.smtp.host")) != null) {\r
76                 MAIL_SMTP = str;\r
77         }\r
78         if ((str = properties.getProperty("mail.smtp.port")) != null) {\r
79                 MAIL_SMTP_PORT = str;\r
80         }\r
81         if ((str = properties.getProperty("mail.smtp.from")) != null) {\r
82                 MAIL_FROM = str;\r
83         }\r
84         if ((str = properties.getProperty("MAIL_TO")) != null) {\r
85                 MAIL_TO = str;\r
86         }\r
87         if ((str = properties.getProperty("MAIL_CC")) != null) {\r
88                 MAIL_CC = str;\r
89         }\r
90         if ((str = properties.getProperty("MAIL_BCC")) != null) {\r
91                 MAIL_BCC = str;\r
92         }\r
93 \r
94         str = properties.getProperty("MAIL_POP_before_SMTP");\r
95         if ((str != null) && str.equals("true")) {\r
96                 POP_before_SMTP = true;\r
97         }\r
98 \r
99         str = properties.getProperty("mail.smtp.auth");\r
100         if ((str != null) && str.equals("true")) {\r
101                 USER_AUTH = true;\r
102         }\r
103 \r
104         str = properties.getProperty("mail.smtp.starttls.enable");\r
105         if ((str != null) && str.equals("true")) {\r
106                 STARTTLS = true;\r
107         }\r
108 \r
109         if ((str = properties.getProperty("MAIL_POP")) != null) {\r
110                 MAIL_POP = str;\r
111         }\r
112         if ((str = properties.getProperty("mail.smtp.user")) != null) {\r
113                 USER_ID = str;\r
114         }\r
115         if ((str = properties.getProperty("MAIL_PASSWORD")) != null) {\r
116                 PASSWORD = str;\r
117         }\r
118     }\r
119 }\r