Merge branch 'main' into lang_de

This commit is contained in:
2022-04-20 10:12:50 +02:00
21 changed files with 614 additions and 302 deletions

View File

@@ -4,10 +4,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.*;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;
import java.util.Properties;
public class SmtpClient {
@@ -19,6 +19,7 @@ public class SmtpClient {
private static final String UTF8 = "UTF-8";
private final String host,password,username;
private final int port;
private boolean forwardUsingListAddress = true;
private Session session;
@@ -29,6 +30,25 @@ public class SmtpClient {
this.port = port;
}
public void bccForward(String from, Message message, List<String> emails) throws MessagingException {
if (session == null) login();
MimeMessage forward = new MimeMessage(session);
forward.setFrom(from);
forward.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(String.join(", ",emails)));
forward.setSubject(message.getSubject());
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(message.getDataHandler());
multipart.addBodyPart(messageBodyPart);
forward.setContent(multipart);
send(forward);
}
public SmtpClient login(){
if (session == null) {
Properties props = new Properties();
@@ -38,7 +58,7 @@ public class SmtpClient {
props.put(SSL, true);
session = Session.getInstance(props);
LOG.debug("Created new session: {}", session);
LOG.debug("Neue Session erzeugt: {}", session);
}
return this;
}
@@ -55,10 +75,14 @@ public class SmtpClient {
message.setText(content,UTF8);
message.setSentDate(new Date());
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(receivers,false));
send(message);
}
public void send(Message message) throws MessagingException {
LOG.debug("Versende Mail…");
Transport.send(message,username,password);
LOG.debug("…versendet");
}
public String host() {
@@ -76,4 +100,5 @@ public class SmtpClient {
public String password() {
return password;
}
}