Stephan Richter
3 years ago
commit
5d8ede756b
3 changed files with 100 additions and 0 deletions
@ -0,0 +1,44 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<groupId>org.example</groupId> |
||||||
|
<artifactId>Widerhall</artifactId> |
||||||
|
<version>1.0-SNAPSHOT</version> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<maven.compiler.source>17</maven.compiler.source> |
||||||
|
<maven.compiler.target>17</maven.compiler.target> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.mail</groupId> |
||||||
|
<artifactId>javax.mail-api</artifactId> |
||||||
|
<version>1.6.2</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>javax</groupId> |
||||||
|
<artifactId>javaee-api</artifactId> |
||||||
|
<version>8.0.1</version> |
||||||
|
<scope>provided</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>ch.qos.logback</groupId> |
||||||
|
<artifactId>logback-classic</artifactId> |
||||||
|
<version>1.3.0-alpha13</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.googlecode.json-simple</groupId> |
||||||
|
<artifactId>json-simple</artifactId> |
||||||
|
<version>1.1.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -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); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue