first version doiing forward with attached original mail
This commit is contained in:
@@ -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 {
|
||||
@@ -29,6 +29,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);
|
||||
var addresses = InternetAddress.parse(String.join(", ",emails));
|
||||
var senders = message.getFrom();
|
||||
forward.setFrom(senders[0]);
|
||||
//forward.setFrom(InternetAddress.parse(from)[0]);
|
||||
forward.setRecipients(Message.RecipientType.BCC,addresses);
|
||||
forward.setSubject(message.getSubject());
|
||||
MimeBodyPart body = new MimeBodyPart();
|
||||
body.setContent(message,"message/rfc822");
|
||||
Multipart multipart = new MimeMultipart();
|
||||
multipart.addBodyPart(body);
|
||||
forward.setContent(multipart);
|
||||
forward.saveChanges();
|
||||
send(forward);
|
||||
}
|
||||
|
||||
|
||||
public SmtpClient login(){
|
||||
if (session == null) {
|
||||
Properties props = new Properties();
|
||||
@@ -55,10 +74,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 +99,5 @@ public class SmtpClient {
|
||||
public String password() {
|
||||
return password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user