working on confirmed subscription
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package de.srsoftware.widerhall.mail;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -9,7 +8,6 @@ import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SmtpClient {
|
||||
@@ -19,23 +17,33 @@ public class SmtpClient {
|
||||
private static final String AUTH = "mail.smtp.auth";
|
||||
private static final String SSL = "mail.smtp.ssl.enable";
|
||||
private static final String UTF8 = "UTF-8";
|
||||
private final String host,password,username;
|
||||
private final int port;
|
||||
|
||||
private Session session;
|
||||
|
||||
public SmtpClient(Map<String,Object> config){
|
||||
String host = (String) config.get("host");
|
||||
long port = (long) config.get("port");
|
||||
Properties props = new Properties();
|
||||
props.put(HOST,host);
|
||||
props.put(PORT,port);
|
||||
props.put(AUTH,true);
|
||||
props.put(SSL,true);
|
||||
|
||||
session = Session.getInstance(props);
|
||||
LOG.debug("Created new {}: {}", getClass().getSimpleName(),session);
|
||||
public SmtpClient(String host, int port, String username, String password){
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void send(JSONObject config, String senderAdress, String senderName, String receivers, String subject, String content) throws MessagingException, UnsupportedEncodingException {
|
||||
public SmtpClient login(){
|
||||
if (session == null) {
|
||||
Properties props = new Properties();
|
||||
props.put(HOST, host);
|
||||
props.put(PORT, port);
|
||||
props.put(AUTH, true);
|
||||
props.put(SSL, true);
|
||||
|
||||
session = Session.getInstance(props);
|
||||
LOG.debug("Created new session: {}", session);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(String senderAdress, String senderName, String receivers, String subject, String content) throws MessagingException, UnsupportedEncodingException {
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.addHeader("Content-Type","text/plain; charset="+UTF8);
|
||||
message.addHeader("format","flowed");
|
||||
@@ -48,12 +56,24 @@ public class SmtpClient {
|
||||
message.setSentDate(new Date());
|
||||
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(receivers,false));
|
||||
|
||||
String username = (String) config.get("user");
|
||||
String password = (String) config.get("password");
|
||||
|
||||
LOG.debug("Versende Mail…");
|
||||
Transport.send(message,username,password);
|
||||
LOG.debug("…versendet");
|
||||
}
|
||||
|
||||
public String host() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public int port() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String username() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String password() {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user