Search in sources :

Example 6 with EmailAddress

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;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) EmailAddress(com.axelor.apps.message.db.EmailAddress) HashSet(java.util.HashSet)

Example 7 with EmailAddress

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);
}
Also used : EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 8 with EmailAddress

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;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) AddressException(javax.mail.internet.AddressException) ArrayList(java.util.ArrayList) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 9 with EmailAddress

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);
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 10 with EmailAddress

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);
}
Also used : TemplateRepository(com.axelor.apps.message.db.repo.TemplateRepository) User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) FullContext(com.axelor.apps.tool.context.FullContext) ArrayList(java.util.ArrayList) EmailAddress(com.axelor.apps.message.db.EmailAddress) Template(com.axelor.apps.message.db.Template)

Aggregations

EmailAddress (com.axelor.apps.message.db.EmailAddress)18 Message (com.axelor.apps.message.db.Message)5 EmailAddressRepository (com.axelor.apps.message.db.repo.EmailAddressRepository)5 User (com.axelor.auth.db.User)3 Transactional (com.google.inject.persist.Transactional)3 ArrayList (java.util.ArrayList)3 ICalendarUser (com.axelor.apps.base.db.ICalendarUser)2 Partner (com.axelor.apps.base.db.Partner)2 ICalendarUserRepository (com.axelor.apps.base.db.repo.ICalendarUserRepository)2 EmailAccount (com.axelor.apps.message.db.EmailAccount)2 Template (com.axelor.apps.message.db.Template)2 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)2 AxelorException (com.axelor.exception.AxelorException)2 HashMap (java.util.HashMap)2 InternetAddress (javax.mail.internet.InternetAddress)2 Address (com.axelor.apps.base.db.Address)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 Lead (com.axelor.apps.crm.db.Lead)1 Employee (com.axelor.apps.hr.db.Employee)1 TemplateRepository (com.axelor.apps.message.db.repo.TemplateRepository)1