use of org.mamute.notification.NotificationMailer.LinkToHelper in project mamute by caelum.
the class NewsletterMailer method sendTo.
public void sendTo(ScrollableResults results, boolean isTestNewsletter) {
DateTime pastWeek = new DateTime().minusWeeks(1);
DateTime twelveHoursAgo = new DateTime().minusHours(12);
List<News> hotNews = news.hotNews();
List<Question> hotQuestions = questions.hot(pastWeek, 8);
List<Question> unanswered = questions.randomUnanswered(pastWeek, twelveHoursAgo, 8);
LinkToHelper linkToHelper = new NotificationMailer.LinkToHelper(router, brutalEnv);
String siteName = bundle.getMessage("site.name");
String date = brutalDateFormat.getInstance("date.joda.newsletter.pattern").print(new DateTime());
String teste = isTestNewsletter ? bundle.getMessage("newsletter_mail_test") : "";
while (results.next()) {
User user = (User) results.get()[0];
try {
Email email = templates.template("newsletter_mail", date, siteName, teste).with("hotNews", hotNews).with("hotQuestions", hotQuestions).with("unansweredQuestions", unanswered).with("unsubscribeLink", linkToHelper.unsubscribeLink(user)).with("linkToHelper", linkToHelper).with("l10n", bundle).with("sanitizer", POLICY).with("siteName", siteName).with("date", date).with("logoUrl", env.get("mail_logo_url")).to(user.getName(), user.getEmail());
email.setCharset("utf-8");
mailer.send(email);
} catch (Exception e) {
LOG.error("could not send email", e);
}
}
}