initial commit
This commit is contained in:
55
src/main/java/de/srsoftware/widerhall/SmtpClient.java
Normal file
55
src/main/java/de/srsoftware/widerhall/SmtpClient.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package de.srsoftware.widerhall;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SmtpClient {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SmtpClient.class);
|
||||
private static final String HOST = "mail.smtp.host";
|
||||
private static final String PORT = "mail.smtp.port";
|
||||
private static final String SOCK = "mail.smtp.socketFactory.port";
|
||||
private static final String CLASS = "mail.smtp.socketFactory.class";
|
||||
private static final String SOCKET_FACTORY = javax.net.ssl.SSLSocketFactory.class.getCanonicalName();
|
||||
private static final String AUTH = "mail.smtp.auth";
|
||||
|
||||
private Session session;
|
||||
|
||||
public void login(String host, int port, String username, String password){
|
||||
Properties props = new Properties();
|
||||
props.put(HOST,host);
|
||||
props.put(PORT,port);
|
||||
props.put(SOCK,port);
|
||||
props.put(AUTH,true);
|
||||
props.put(CLASS,SOCKET_FACTORY);
|
||||
|
||||
Authenticator auth = new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username,password);
|
||||
}
|
||||
};
|
||||
|
||||
session = Session.getDefaultInstance(props,auth);
|
||||
LOG.debug("Created new session: {}", session);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, ParseException {
|
||||
var parser = new JSONParser();
|
||||
var config = Files.readString(new File("/tmp/config.json").toPath());
|
||||
LOG.debug("config: {}",config);
|
||||
var json = parser.parse(config);
|
||||
LOG.debug("json: {}",json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user