You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
package de.srsoftware.widerhall.mail; |
|
|
|
import org.json.simple.JSONObject; |
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
|
|
import javax.mail.Message; |
|
import javax.mail.MessagingException; |
|
import java.io.UnsupportedEncodingException; |
|
|
|
public class Forwarder implements MessageHandler { |
|
private static final Logger LOG = LoggerFactory.getLogger(Forwarder.class); |
|
private final SmtpClient smtp; |
|
private final String receiver,sender; |
|
|
|
public Forwarder(String host, int port, String username, String password, String sender, String receiver) { |
|
this.sender = sender; |
|
this.receiver = receiver; |
|
SmtpClient smtp = new SmtpClient(host,port,username,password); |
|
this.smtp = smtp; |
|
} |
|
|
|
@Override |
|
public void onMessageReceived(Message message) throws MessagingException { |
|
LOG.debug("forwarding {}",message.getSubject()); |
|
|
|
try { |
|
smtp.send(sender,"Stephan Richter",receiver,"Info: "+message.getSubject(),"Neue Mail eingegangen!"); |
|
} catch (UnsupportedEncodingException e) { |
|
e.printStackTrace(); |
|
} |
|
} |
|
}
|
|
|