Search in sources :

Example 1 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class BatchEventReminder method findOrCreateEmailAddress.

@Transactional
protected EmailAddress findOrCreateEmailAddress(String email, String name) {
    EmailAddress emailAddress = emailAddressRepo.all().filter("self.name = '" + name + "'").fetchOne();
    if (emailAddress == null) {
        emailAddress = new EmailAddress();
        emailAddress.setAddress(email);
        emailAddress = emailAddressRepo.save(emailAddress);
    }
    return emailAddress;
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress) Transactional(com.google.inject.persist.Transactional)

Example 2 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class ICalendarService method findOrCreateUser.

public ICalendarUser findOrCreateUser(User user) {
    String email = null;
    if (user.getPartner() != null && user.getPartner().getEmailAddress() != null && !Strings.isNullOrEmpty(user.getPartner().getEmailAddress().getAddress())) {
        email = user.getPartner().getEmailAddress().getAddress();
    } else if (!Strings.isNullOrEmpty(user.getEmail())) {
        email = user.getEmail();
    } else {
        return null;
    }
    ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
    ICalendarUser icalUser = null;
    icalUser = repo.all().filter("self.email = ?1 AND self.user.id = ?2", email, user.getId()).fetchOne();
    if (icalUser == null) {
        icalUser = repo.all().filter("self.user.id = ?1", user.getId()).fetchOne();
    }
    if (icalUser == null) {
        icalUser = repo.all().filter("self.email = ?1", email).fetchOne();
    }
    if (icalUser == null) {
        icalUser = new ICalendarUser();
        icalUser.setEmail(email);
        icalUser.setName(user.getFullName());
        EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
        if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
            icalUser.setUser(emailAddress.getPartner().getUser());
        }
    }
    return icalUser;
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarUserRepository(com.axelor.apps.base.db.repo.ICalendarUserRepository)

Example 3 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class SyncContactService method importEmailAddress.

protected void importEmailAddress(Person googlePerson, Partner partner, Boolean updateContactField) {
    if (googlePerson.getEmailAddresses() == null) {
        return;
    }
    com.google.api.services.people.v1.model.EmailAddress googleEmail = Mapper.toBean(com.google.api.services.people.v1.model.EmailAddress.class, googlePerson.getEmailAddresses().get(0));
    if (Strings.isNullOrEmpty(googleEmail.getValue()) || !EmailTool.isValidEmailAddress(googleEmail.getValue())) {
        return;
    }
    if (partner.getEmailAddress() == null || Strings.isNullOrEmpty(partner.getEmailAddress().getAddress())) {
        EmailAddress partnerEmail = createEmailAddress(googleEmail.getValue());
        partnerEmail.setPartner(partner);
        partner.setEmailAddress(partnerEmail);
    } else {
        if (!partner.getEmailAddress().getAddress().equalsIgnoreCase(googleEmail.getValue())) {
            if (updateContactField) {
                EmailAddress partnerEmail = createEmailAddress(googleEmail.getValue());
                updateDescription(partner, I18n.get(SYNC_CONTACT_OLD_EMAIL), partner.getEmailAddress().getAddress());
                partnerEmail.setPartner(partner);
                partner.setEmailAddress(partnerEmail);
            } else {
                updateDescription(partner, I18n.get(SYNC_CONTACT_GOOGLE_EMAIL), googleEmail.getValue());
            }
        }
    }
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 4 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class TemplateMessageServiceImpl method generateMessage.

protected Message generateMessage(String model, Long objectId, Template template, Templates templates, Map<String, Object> templatesContext, Boolean isForTemporaryEmail) {
    String content = "";
    String subject = "";
    String replyToRecipients = "";
    String toRecipients = "";
    String ccRecipients = "";
    String bccRecipients = "";
    String addressBlock = "";
    int mediaTypeSelect;
    String signature = "";
    if (!Strings.isNullOrEmpty(template.getContent())) {
        content = templates.fromText(template.getContent()).make(templatesContext).render();
    }
    if (!Strings.isNullOrEmpty(template.getAddressBlock())) {
        addressBlock = templates.fromText(template.getAddressBlock()).make(templatesContext).render();
    }
    if (!Strings.isNullOrEmpty(template.getSubject())) {
        subject = templates.fromText(template.getSubject()).make(templatesContext).render();
        log.debug("Subject ::: {}", subject);
    }
    if (!Strings.isNullOrEmpty(template.getReplyToRecipients())) {
        replyToRecipients = templates.fromText(template.getReplyToRecipients()).make(templatesContext).render();
        log.debug("Reply to ::: {}", replyToRecipients);
    }
    if (template.getToRecipients() != null) {
        toRecipients = templates.fromText(template.getToRecipients()).make(templatesContext).render();
        log.debug("To ::: {}", toRecipients);
    }
    if (template.getCcRecipients() != null) {
        ccRecipients = templates.fromText(template.getCcRecipients()).make(templatesContext).render();
        log.debug("CC ::: {}", ccRecipients);
    }
    if (template.getBccRecipients() != null) {
        bccRecipients = templates.fromText(template.getBccRecipients()).make(templatesContext).render();
        log.debug("BCC ::: {}", bccRecipients);
    }
    mediaTypeSelect = this.getMediaTypeSelect(template);
    log.debug("Media ::: {}", mediaTypeSelect);
    if (template.getSignature() != null) {
        signature = templates.fromText(template.getSignature()).make(templatesContext).render();
        log.debug("Signature ::: {}", signature);
    }
    EmailAccount mailAccount = getMailAccount();
    EmailAddress fromAddress = null;
    if (mailAccount == null) {
        TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MAIL_ACCOUNT_6)));
    } else {
        fromAddress = getEmailAddress(mailAccount.getFromAddress());
    }
    Message message = messageService.createMessage(model, Math.toIntExact(objectId), subject, content, fromAddress, getEmailAddresses(replyToRecipients), getEmailAddresses(toRecipients), getEmailAddresses(ccRecipients), getEmailAddresses(bccRecipients), null, addressBlock, mediaTypeSelect, mailAccount, signature, isForTemporaryEmail);
    return message;
}
Also used : AxelorException(com.axelor.exception.AxelorException) EmailAccount(com.axelor.apps.message.db.EmailAccount) Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 5 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class MailAccountServiceImpl method getEmailAddress.

private EmailAddress getEmailAddress(InternetAddress address) {
    EmailAddress emailAddress = null;
    emailAddress = emailAddressRepo.findByAddress(address.getAddress());
    if (emailAddress == null) {
        emailAddress = new EmailAddress();
        emailAddress.setAddress(address.getAddress());
    }
    return emailAddress;
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress)

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