X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fanalyze%2FNotifier.java;h=bf92fc107368607e4a1cccfc07b3045051fe2684;hb=a4a577abc3f9b2b1147caafd1cb39fa8c2622cd4;hp=62037279f6005e8b1252a0d13c71955b9146de48;hpb=f829b23412e21d657d63a81897794e833ef162ab;p=cfb.git diff --git a/prod/net/jaekl/cfb/analyze/Notifier.java b/prod/net/jaekl/cfb/analyze/Notifier.java index 6203727..bf92fc1 100644 --- a/prod/net/jaekl/cfb/analyze/Notifier.java +++ b/prod/net/jaekl/cfb/analyze/Notifier.java @@ -3,20 +3,14 @@ package net.jaekl.cfb.analyze; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Properties; - -import javax.mail.Message.RecipientType; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; import net.jaekl.cfb.CfbBundle; import net.jaekl.cfb.Config; +import net.jaekl.qd.util.MailException; +import net.jaekl.qd.util.MimePart; +import net.jaekl.qd.util.SendMail; public class Notifier { - private static final String MAIL_SMTP_HOST = "mail.smtp.host"; private static final String TEXT_HTML = "text/html"; CfbBundle m_bundle; @@ -35,9 +29,9 @@ public class Notifier { } void sendEmail(PrintWriter pw, HtmlReport report) { - Properties props = System.getProperties(); - props.setProperty(MAIL_SMTP_HOST, m_config.getMailSmtpHost()); - Session sess = Session.getDefaultInstance(props); + SendMail sendMail = new SendMail(); + + sendMail.setSmtpHost(m_config.getMailSmtpHost()); ArrayList recipients = m_config.getNotify(); if (recipients.size() < 1) { @@ -47,27 +41,26 @@ public class Notifier { PrintWriter mailWriter = null; try { - MimeMessage msg = new MimeMessage(sess); - String earlier = report.getDelta().getEarlier().constructVersionText(m_bundle); String later = report.getDelta().getLater().constructVersionText(m_bundle); - msg.setFrom(new InternetAddress(m_config.getMailFrom())); - msg.setSubject(m_bundle.get(CfbBundle.CFB_MAIL_SUBJECT, earlier, later)); + sendMail.setFrom(m_config.getMailFrom()); + sendMail.setSubject(m_bundle.get(CfbBundle.CFB_MAIL_SUBJECT, earlier, later)); for (String recipient : recipients) { - msg.addRecipient(RecipientType.TO, new InternetAddress(recipient)); + sendMail.addTo(recipient); } StringWriter sw = new StringWriter(); mailWriter = new PrintWriter(sw); report.write(mailWriter); mailWriter.flush(); - - msg.setContent(sw.toString(), TEXT_HTML); - Transport.send(msg); + + MimePart part = new MimePart(TEXT_HTML, sw.toString()); + sendMail.addPart(part); + sendMail.send(); } - catch (MessagingException exc) { + catch (MailException exc) { StringBuilder toList = new StringBuilder(); for (String recipient : recipients) { if (toList.length() > 0) {