initial commit

This commit is contained in:
2022-04-13 12:17:15 +02:00
commit 5d8ede756b
3 changed files with 100 additions and 0 deletions

View 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);
}
}