[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:
parent
7a090f3d68
commit
bdd4091a16
|
@ -135,12 +135,22 @@ public class SmtpMailer {
|
||||||
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
|
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
|
||||||
|
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
|
|
||||||
|
if (this.overrideRecipient != null)
|
||||||
|
text = "Override recipient. Original recipient " + recipient + ".\n\n" + text;
|
||||||
message.setText(text);
|
message.setText(text);
|
||||||
|
|
||||||
Transport.send(message);
|
Transport.send(message);
|
||||||
|
|
||||||
logger.info(MessageFormat.format("Sent E-mail to {0}: {1}",
|
String msg;
|
||||||
message.getRecipients(Message.RecipientType.TO)[0], message.getSubject()));
|
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) {
|
} catch (MessagingException e) {
|
||||||
throw new RuntimeException("Failed to send e-mail due to " + e.getMessage(), e);
|
throw new RuntimeException("Failed to send e-mail due to " + e.getMessage(), e);
|
||||||
|
|
Loading…
Reference in New Issue