@Override public void onApplicationEvent(ShutdownMessage sm) { if (!isEnabled()) { return; } Set<String> addresses = getAllSystemUsers(true); sendBlind(addresses, "Server shutdown"); }
@Override public void handleContextRefreshedEvent(ContextRefreshedEvent event) { if (!sender.isEnabled()) { return; } Set<String> addresses = sender.getAllSystemUsers(true); sender.sendBlind(addresses, "Server started"); }
protected void sendBlind(Set<String> addresses, String subject) { sendBlind(addresses, subject, getDefaultBody()); }
protected void sendBlind(Set<String> addresses, String subject, String body) { if (!isEnabled()) { // Printing warning since the enabled mail check should happen // as early as possible to prevent wasting resources. log.warn("sendBlind called when mail is disabled."); return; } if (addresses == null || addresses.isEmpty()) { log.debug("No emails found."); return; } for (String address : addresses) { try { // TODO: send in background thread getMailUtil().sendEmail(address, getSubjectPrefix() + subject, body, false /* not html */, null, null); } catch (Exception e) { log.error("Failed to send email: {} ", address, e); } } }
@Override public void onApplicationEvent(LoginAttemptMessage lam) { if (!isEnabled()) { return; } if (lam.success == null || lam.success) { return; } final String subj = String.format("Login failed for '%s'", lam.user); final boolean hasSpecific = (!isEmpty(onSpecificUsers) && onSpecificUsers.contains(lam.user)); if (onAllUsers || hasSpecific) { if (contactSystem) { sendBlind(getAllSystemUsers(false), subj); } if (contactUser) { sendBlind(Collections.singleton(getUserEmail(lam.user)), subj); } } }
protected void sendEmail(Collection<EventLog> matches) { Parameters p = new Parameters(); Roles roles = getRoles(); p.addString("systemGroup", roles.getSystemGroupName()); p.addLong("systemGroupId", roles.getSystemGroupId()); sb.append("\n"); for (IObject obj : getQueryService().findAllByQuery(queryString, p)) { if (obj instanceof Experimenter) { addUser(addresses, (Experimenter) obj); } else if (obj instanceof ExperimenterGroup) { for (Experimenter exp : ((ExperimenterGroup) obj) .linkedExperimenterList()) { addUser(addresses, exp); sendBlind(addresses, String.format("%s %s notification", action, klass.getSimpleName()), sb.toString());
@RolesAllowed("user") @Transactional(readOnly = false) public void notifyMembersOfShare(long shareId, String subject, String message, boolean html) { EventContext ec = getSecuritySystem().getEventContext(); Set<Experimenter> exps = getAllMembers(shareId); exps.add(getShare(shareId).getOwner()); Map<Experimenter, String> errors = new HashMap<Experimenter, String>(); for (final Experimenter e : exps) { if (e.getId() != ec.getCurrentUserId() && e.getEmail() != null && mailUtil.validateEmail(e.getEmail())) { try { mailUtil.sendEmail(e.getEmail(), subject, message, html, null, null); } catch (MailException me) { errors.put(e, me.getMessage()); } } } if (!errors.isEmpty()) { log.error(ServiceHandler.getResultsString(errors, null)); } }
/** * Overloaded method which takes typical email fields as arguments, to * prepare and populate the given new MimeMessage instance and send. Sender * of the email is loaded from omero.mail.from * * @param to * email address message is sent to * @param topic * topic of the message * @param body * body of the message * @param html * flag determines the content type to apply. * @param ccrecipients * list of email addresses message is sent as copy to * @param bccrecipients * list of email addresses message is sent as blind copy to */ public void sendEmail(final String to, final String topic, final String body, final boolean html, final List<String> ccrecipients, final List<String> bccrecipients) { this.sendEmail(sender, to, topic, body, html, ccrecipients, bccrecipients); }
private List<String> parseExtraRecipients() { Set<String> extraRecipients = new HashSet<String>(); for (final String e : extra) { if (mailUtil.validateEmail(e)) { extraRecipients.add(e); } else { rsp.invalidemails.add(e); } } return new ArrayList<String>(extraRecipients); }
protected Set<String> getAllSystemUsers(boolean newTx) { Set<String> addresses = new HashSet<String>(); if (newTx) { loadFromAction(addresses); } else { loadFromQuery(addresses); } return addresses; }
private void loadFromQuery(Set<String> addresses) { for (Object[] o : getQueryService().projection( "select e.email from Experimenter e " + "join e.groupExperimenterMap m " + "join m.parent g where g.id = :id", new Parameters().addId(getRoles().getSystemGroupId()))) { if (o != null && o.length >= 1 && o[0] != null) { String email = o[0].toString(); if (!email.isEmpty()) { addresses.add(email); } } } }
public void init(Helper helper) { this.helper = helper; this.sender = mailUtil.getSender(); if (omename == null) throw helper.cancel(new ERR(), null, "no-omename"); if (email == null) throw helper.cancel(new ERR(), null, "no-email"); helper.allowGuests(); this.helper.setSteps(1); }
protected String getUserEmail(String user) { Experimenter e = getQueryService().findByString(Experimenter.class, "omeName", user); if (e == null) { return null; } return e.getEmail(); }
@Transactional(readOnly=false) @Override public Object doWork(Session session, ServiceFactory sf) { MapAnnotation ma = new MapAnnotation(); ma.setNs(NAMESPACE); ma.setDescription(parseStream(stream)); ma.setMapValue(new ArrayList<NamedValue>()); ma.getMapValue().add(new NamedValue("from", from)); ma.getMapValue().add(new NamedValue("to", recipient)); ma = sf.getUpdateService().saveAndReturnObject(ma); log.info("Saved email: MapAnnotation:" + ma.getId()); return ma; }}); }
public Object step(int step) throws Cancel { helper.assertStep(step); // early exist try { this.recipients.get(step); } catch (IndexOutOfBoundsException e) { return null; } String email = this.recipients.get(step); try { mailUtil.sendEmail(this.sender, email, subject, body, html, null, null); } catch (MailException me) { log.error(me.getMessage()); rsp.invalidemails.add(email); } rsp.success+=1; return null; }
if (e.getEmail() != null && mailUtil.validateEmail(e.getEmail())) { recipients.add(e.getEmail()); } else {
"ApiUsageException", String.format("No recipients specified.")); this.sender = mailUtil.getSender(); if (StringUtils.isBlank(this.sender)) throw helper.cancel(new ERR(), null, "no-sender",
mailUtil.sendEmail(sender, e.getEmail(), subject, body, false, null, null); log.info("sent new password for {} to {}", e.getOmeName(), e.getEmail());