[New] Implemented a SmtpMailer and Strolch MailHandler component

SmtpMailer is a singleton and requires properties.

Configure the MailHandler as follows:
<Component>
    <name>MailHandler</name>
    <api>li.strolch.handler.mail.MailHandler</api>
    <impl>li.strolch.handler.mail.SmtpMailHandler</impl>
    <Properties>
        <fromAddr>relayer@eitchnet.ch</fromAddr>
        <fromName>Consilium</fromName>
        <overrideRecipientAddr>eitch@eitchnet.ch</overrideRecipientAddr>
        <overrideRecipientName>Consilium Test</overrideRecipientName>
        <username>relayer@eitchnet.ch</username>
        <password>M5ztAE4a1NWWZBHaUd2ey9aoH</password>
        <auth>true</auth>
        <startTls>true</startTls>
        <host>smtp.gmail.com</host>
        <port>587</port>
    </Properties>
</Component>
This commit is contained in:
Robert von Burg 2016-09-08 14:24:10 +02:00
parent 7a090f3d68
commit bdd4091a16
1 changed files with 12 additions and 2 deletions

View File

@ -135,12 +135,22 @@ public class SmtpMailer {
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
message.setSubject(subject);
if (this.overrideRecipient != null)
text = "Override recipient. Original recipient " + recipient + ".\n\n" + text;
message.setText(text);
Transport.send(message);
logger.info(MessageFormat.format("Sent E-mail to {0}: {1}",
message.getRecipients(Message.RecipientType.TO)[0], message.getSubject()));
String msg;
if (this.overrideRecipient != null)
msg = MessageFormat.format("Sent E-mail to override recipient {0}: {1}",
message.getRecipients(Message.RecipientType.TO)[0], message.getSubject());
else {
msg = MessageFormat.format("Sent E-mail to {0}: {1}",
message.getRecipients(Message.RecipientType.TO)[0], message.getSubject());
}
logger.info(msg);
} catch (MessagingException e) {
throw new RuntimeException("Failed to send e-mail due to " + e.getMessage(), e);