P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package foundation.send.mail;
 
import java.util.Properties;
 
import javax.mail.PasswordAuthentication;
 
import org.dom4j.Element;
 
import foundation.json.IJSONWriter;
 
 
public class MailServer {
 
    private String name;
    private String debug;
    private String host;
    private String protocol;
    private String smtpAuth;
    private String port;
    private String account;
    private String password;
    private Properties propertys;
    
    public MailServer() {
        propertys = new Properties();
    }
    
    public void load(Element element) {
        name = element.attributeValue("name");
        debug = element.attributeValue("debug");
        host = element.elementText("host");
        protocol = element.elementText("protocol");
        smtpAuth = element.elementText("auth");
        port = element.elementText("port");
        account = element.elementText("account");
        password = element.elementText("password");
        
        init();
    }
    
    public void init() {
        propertys.clear();
        
        propertys.setProperty("mail.debug", debug);
        propertys.setProperty("mail.host", host);
        propertys.setProperty("mail.transport.protocol", protocol);
        propertys.setProperty("mail.smtp.auth", smtpAuth);
        
        propertys.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        propertys.setProperty("mail.smtp.socketFactory.fallback", "false");
        propertys.setProperty("mail.smtp.socketFactory.port", port);
    }
 
    public Properties getPropertys() {
        return propertys;
    }
 
    public Authenticator getAuthenticator() {
        return new Authenticator();
    }
    
    public String getAccount() {
        return account;
    }
 
    public String getPassword() {
        return password;
    }
    
    public class Authenticator extends javax.mail.Authenticator {
 
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(getAccount(), getPassword());
        }
        
    }
 
    public String getName() {
        return name;
    }
 
    public void writeJSONBody(IJSONWriter writer) {
        // TODO Auto-generated method stub
        
    }
}