Search in sources :

Example 1 with LinkToHelper

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);
        }
    }
}
Also used : User(org.mamute.model.User) Email(org.apache.commons.mail.Email) News(org.mamute.model.News) Question(org.mamute.model.Question) LinkToHelper(org.mamute.notification.NotificationMailer.LinkToHelper) DateTime(org.joda.time.DateTime)

Aggregations

Email (org.apache.commons.mail.Email)1 DateTime (org.joda.time.DateTime)1 News (org.mamute.model.News)1 Question (org.mamute.model.Question)1 User (org.mamute.model.User)1 LinkToHelper (org.mamute.notification.NotificationMailer.LinkToHelper)1