|
|
@ -33,6 +33,9 @@ import org.thingsboard.server.extensions.core.action.mail.SendMailActionMsg; |
|
|
import javax.mail.MessagingException; |
|
|
import javax.mail.MessagingException; |
|
|
import javax.mail.internet.MimeMessage; |
|
|
import javax.mail.internet.MimeMessage; |
|
|
import java.util.Properties; |
|
|
import java.util.Properties; |
|
|
|
|
|
import java.util.concurrent.Executor; |
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author Andrew Shvayka |
|
|
* @author Andrew Shvayka |
|
|
@ -41,6 +44,9 @@ import java.util.Properties; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class MailPlugin extends AbstractPlugin<MailPluginConfiguration> implements RuleMsgHandler { |
|
|
public class MailPlugin extends AbstractPlugin<MailPluginConfiguration> implements RuleMsgHandler { |
|
|
|
|
|
|
|
|
|
|
|
//TODO: Add logic to close this executor on shutdown.
|
|
|
|
|
|
private static final ExecutorService executor = Executors.newSingleThreadExecutor(); |
|
|
|
|
|
|
|
|
private MailPluginConfiguration configuration; |
|
|
private MailPluginConfiguration configuration; |
|
|
private JavaMailSenderImpl mailSender; |
|
|
private JavaMailSenderImpl mailSender; |
|
|
|
|
|
|
|
|
@ -84,12 +90,14 @@ public class MailPlugin extends AbstractPlugin<MailPluginConfiguration> implemen |
|
|
@Override |
|
|
@Override |
|
|
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException { |
|
|
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException { |
|
|
if (msg.getPayload() instanceof SendMailActionMsg) { |
|
|
if (msg.getPayload() instanceof SendMailActionMsg) { |
|
|
try { |
|
|
executor.submit(() -> { |
|
|
sendMail((SendMailActionMsg) msg.getPayload()); |
|
|
try { |
|
|
} catch (Exception e) { |
|
|
sendMail((SendMailActionMsg) msg.getPayload()); |
|
|
log.warn("Failed to send email", e); |
|
|
} catch (Exception e) { |
|
|
throw new RuleException("Failed to send email", e); |
|
|
log.warn("[{}] Failed to send email", ctx.getPluginId(), e); |
|
|
} |
|
|
ctx.persistError("Failed to send email", e); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
throw new RuntimeException("Not supported msg type: " + msg.getPayload().getClass() + "!"); |
|
|
throw new RuntimeException("Not supported msg type: " + msg.getPayload().getClass() + "!"); |
|
|
} |
|
|
} |
|
|
|