commit 5d8ede756b4c5f4b01754e41c7924527e525f75d Author: Stephan Richter Date: Wed Apr 13 12:17:15 2022 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..244b293 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + org.example + Widerhall + 1.0-SNAPSHOT + + + 17 + 17 + + + + + javax.mail + javax.mail-api + 1.6.2 + + + + javax + javaee-api + 8.0.1 + provided + + + + ch.qos.logback + logback-classic + 1.3.0-alpha13 + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + \ No newline at end of file diff --git a/src/main/java/de/srsoftware/widerhall/SmtpClient.java b/src/main/java/de/srsoftware/widerhall/SmtpClient.java new file mode 100644 index 0000000..2612286 --- /dev/null +++ b/src/main/java/de/srsoftware/widerhall/SmtpClient.java @@ -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); + } +}