use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class MailAccountServiceImpl method getEmailAddressSet.
private Set<EmailAddress> getEmailAddressSet(List<InternetAddress> addresses) {
Set<EmailAddress> addressSet = new HashSet<>();
if (addresses == null) {
return addressSet;
}
for (InternetAddress address : addresses) {
EmailAddress emailAddress = getEmailAddress(address);
addressSet.add(emailAddress);
}
return addressSet;
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class MailServiceMessageImpl method resolve.
@Override
public Model resolve(String email) {
final EmailAddressRepository addresses = Beans.get(EmailAddressRepository.class);
final EmailAddress address = addresses.all().filter("self.address = ?1", email).fetchOne();
if (address != null) {
return address;
}
return super.resolve(email);
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class MailServiceMessageImpl method findEmails.
@Override
public List<InternetAddress> findEmails(String matching, List<String> selected, int maxResult) {
final List<String> where = new ArrayList<>();
final Map<String, Object> params = new HashMap<>();
where.add("self.address is not null");
if (!isBlank(matching)) {
where.add("(LOWER(self.address) like LOWER(:email))");
params.put("email", "%" + matching + "%");
}
if (selected != null && !selected.isEmpty()) {
where.add("self.address not in (:selected)");
params.put("selected", selected);
}
final String filter = Joiner.on(" AND ").join(where);
final Query<EmailAddress> query = Query.of(EmailAddress.class);
if (!isBlank(filter)) {
query.filter(filter);
query.bind(params);
}
final List<InternetAddress> addresses = new ArrayList<>();
for (EmailAddress emailAddress : query.fetch(maxResult)) {
try {
final InternetAddress item = new InternetAddress(emailAddress.getAddress());
addresses.add(item);
} catch (AddressException e) {
}
}
return addresses;
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class SyncContactService method createEmailAddress.
protected EmailAddress createEmailAddress(String googleEmail) {
EmailAddress email = new EmailAddress();
email.setAddress(googleEmail);
email.setName(googleEmail);
email.setImportOrigin(importOrigin);
return emailAddressRepo.save(email);
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class WkfEmailServiceImpl method sendEmail.
@Override
public void sendEmail(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException, MessagingException, AxelorException, InstantiationException, IllegalAccessException, IOException {
String title = wkfTaskConfig.getTaskEmailTitle();
if (title == null) {
return;
}
FullContext wkfContext = wkfUserActionService.getModelCtx(wkfTaskConfig, execution);
if (wkfContext == null) {
return;
}
String model = null;
String tag = null;
Long id = null;
title = wkfUserActionService.processTitle(title, wkfContext);
model = wkfContext.getTarget().getClass().getName();
if (wkfContext.getTarget().getClass().equals(MetaJsonRecord.class)) {
tag = (String) wkfContext.get("jsonModel");
model = tag;
} else {
tag = wkfContext.getTarget().getClass().getSimpleName();
}
id = (Long) wkfContext.get("id");
String url = createUrl(wkfContext, wkfTaskConfig.getDefaultForm());
String activeNode = execution.getCurrentActivityName();
Template template = Beans.get(TemplateRepository.class).findByName(wkfTaskConfig.getTemplateName());
Message message = null;
if (template != null) {
url = "<a href=\"" + url + "\" >" + url + "</a>";
message = Beans.get(TemplateMessageService.class).generateMessage(id, model, tag, template);
message.setSubject(message.getSubject().replace("{{activeNode}}", activeNode));
message.setContent(message.getContent().replace("{{activeNode}}", activeNode));
message.setSubject(message.getSubject().replace("{{recordUrl}}", url));
message.setContent(message.getContent().replace("{{recordUrl}}", url));
} else {
User user = null;
if (wkfTaskConfig.getUserPath() != null) {
user = wkfUserActionService.getUser(wkfTaskConfig.getUserPath(), wkfContext);
}
if (user == null || user.getEmail() == null) {
return;
}
String content = String.format(EMAIL_CONTENT, user.getName(), activeNode, url, url);
List<EmailAddress> toEmailAddressList = new ArrayList<EmailAddress>();
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(user.getEmail());
if (emailAddress == null) {
emailAddress = new EmailAddress(user.getEmail());
}
toEmailAddressList.add(emailAddress);
message = messageService.createMessage(model, id, title, content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, null, null);
}
messageService.sendByEmail(message);
}
Aggregations