use of org.activityinfo.server.mail.Message in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method createNewUser.
private User createNewUser(User executingUser, UserPermissionDTO dto) {
if (executingUser.getId() == 0) {
throw new AssertionError("executingUser.id == 0!");
}
if (executingUser.getName() == null) {
throw new AssertionError("executingUser.name == null!");
}
User user = UserDAOImpl.createNewUser(dto.getEmail(), dto.getName(), executingUser.getLocale());
user.setInvitedBy(executingUser);
userDAO.persist(user);
try {
Message message = mailSender.createMessage(new InvitationMessage(user, executingUser));
message.replyTo(executingUser.getEmail(), executingUser.getName());
mailSender.send(message);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not send invitation mail", e);
throw new CommandException("Failed to send invitation email");
}
return user;
}
use of org.activityinfo.server.mail.Message in project activityinfo by bedatadriven.
the class ReportMailer method mailReport.
private void mailReport(ReportSubscription sub, Report report, Date today, byte[] content) throws IOException, SAXException, MessagingException {
LOGGER.log(Level.INFO, "Sending email to " + sub.getUser().getEmail());
DateFormat reportDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, sub.getUser().getLocaleObject());
Message email = new Message();
email.to(sub.getUser().getEmail(), sub.getUser().getName());
email.subject("ActivityInfo: " + report.getTitle());
email.body(ReportMailerHelper.composeTextEmail(sub, report));
email.addAttachment().withContent(content, "text/enriched").withFileName(report.getContent().getFileName() + " " + reportDateFormat.format(today) + ".rtf");
mailer.send(email);
}
use of org.activityinfo.server.mail.Message in project activityinfo by bedatadriven.
the class DigestMessageBuilder method build.
public Message build() throws IOException, MessagingException {
Preconditions.checkNotNull(userDigest);
Preconditions.checkNotNull(userDigest.getUser());
// set the locale of the messages
ThreadLocalLocaleProvider.pushLocale(userDigest.getUser().getLocaleObject());
try {
DigestModel model = digestModelBuilder.createModel(userDigest);
if (!model.hasData()) {
return null;
}
// create message, set recipient & bcc
Message message = new Message();
message.to(userDigest.getUser().getEmail(), userDigest.getUser().getName());
String subject = I18N.MESSAGES.digestSubject(userDigest.getDate());
message.subject(subject);
// create the html body
HtmlWriter htmlWriter = new HtmlWriter();
htmlWriter.startDocument();
htmlWriter.startDocumentHeader();
htmlWriter.documentTitle(subject);
htmlWriter.open(new HtmlTag("style")).at("type", "text/css").text("body { font-family:Helvetica; } a {color: black; text-decoration:none;} ").close();
htmlWriter.endDocumentHeader();
htmlWriter.startDocumentBody();
htmlWriter.paragraph(I18N.MESSAGES.digestGreeting(userDigest.getUser().getName()));
// the digest content
htmlWriter.paragraph(digestRenderer.renderHtml(model));
String signature = I18N.MESSAGES.digestSignature();
htmlWriter.paragraph(signature);
htmlWriter.endDocumentBody();
htmlWriter.endDocument();
LOGGER.finest("digest:\n" + htmlWriter.toString());
message.htmlBody(htmlWriter.toString());
return message;
} finally {
ThreadLocalLocaleProvider.popLocale();
}
}
use of org.activityinfo.server.mail.Message in project activityinfo by bedatadriven.
the class UserDigestResource method createUserDigest.
@GET
@Produces(MediaType.TEXT_HTML)
public String createUserDigest(@QueryParam(PARAM_USER) int userId, @QueryParam(PARAM_NOW) Long now, @QueryParam(PARAM_DAYS) int days, @QueryParam(PARAM_SENDEMAIL) @DefaultValue(PARAM_SENDEMAIL_DEF) boolean sendEmail) throws IOException, MessagingException {
if (userId <= 0) {
return "no user specified";
}
Date date = now == null ? new Date() : new Date(now);
if (days <= 0) {
days = getDefaultDays();
}
User user = entityManager.get().find(User.class, userId);
if (!user.isEmailNotification()) {
return "user's email notification flag is set to false.";
}
UserToken userToken = UserTokenManager.create(userId, UserTokenScope.SUBSCRIBE, UserTokenScope.UNSUBSCRIBE);
authProvider.set(user);
LOGGER.info("creating digest for " + user.getEmail() + " on " + DateFormatter.formatDateTime(date) + " for activity period: " + days + " day(s)." + " (sending email: " + sendEmail + ")");
UserDigest userDigest = new UserDigest(user, date, days, userToken.getSecureToken());
DigestMessageBuilder digest = new DigestMessageBuilder(digestModelBuilder, digestRenderer);
digest.setUserDigest(userDigest);
Message message = digest.build();
if (message != null && sendEmail) {
mailSender.get().send(message);
}
return message == null ? "no updates found" : message.getHtmlBody();
}
Aggregations