Search in sources :

Example 11 with EmailAddress

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

the class AppraisalServiceImpl method send.

@Transactional(rollbackOn = { Exception.class })
@Override
public void send(Appraisal appraisal) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
    Employee employee = appraisal.getEmployee();
    User user = employee.getUser();
    if (user != null) {
        mailFollowerRepo.follow(appraisal, user);
    }
    Template template = templateRepo.all().filter("self.metaModel.fullName = ?1", Appraisal.class.getName()).fetchOne();
    EmailAddress email = null;
    if (employee.getContactPartner() != null) {
        email = employee.getContactPartner().getEmailAddress();
    }
    if (template != null && email != null) {
        Message message = templateMessageService.generateMessage(appraisal, template);
        message.addToEmailAddressSetItem(email);
        messageService.sendByEmail(message);
    }
    appraisal.setStatusSelect(AppraisalRepository.STATUS_SENT);
    appraisalRepo.save(appraisal);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) EmailAddress(com.axelor.apps.message.db.EmailAddress) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 12 with EmailAddress

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

the class PartnerServiceImpl method createPartner.

public Partner createPartner(String name, String firstName, String fixedPhone, String mobilePhone, EmailAddress emailAddress, Currency currency, Address deliveryAddress, Address mainInvoicingAddress, boolean createContact) {
    Partner partner = new Partner();
    partner.setName(name);
    partner.setFirstName(firstName);
    partner.setPartnerTypeSelect(PartnerRepository.PARTNER_TYPE_COMPANY);
    partner.setIsProspect(true);
    partner.setFixedPhone(fixedPhone);
    partner.setMobilePhone(mobilePhone);
    partner.setEmailAddress(emailAddress);
    partner.setCurrency(currency);
    this.setPartnerFullName(partner);
    if (createContact) {
        Partner contact = this.createContact(partner, name, firstName, fixedPhone, mobilePhone, emailAddress != null ? new EmailAddress(emailAddress.getAddress()) : null, mainInvoicingAddress);
        partner.addContactPartnerSetItem(contact);
    }
    if (deliveryAddress == mainInvoicingAddress) {
        addPartnerAddress(partner, mainInvoicingAddress, true, true, true);
    } else {
        addPartnerAddress(partner, deliveryAddress, true, false, true);
        addPartnerAddress(partner, mainInvoicingAddress, true, true, false);
    }
    return partner;
}
Also used : Partner(com.axelor.apps.base.db.Partner) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 13 with EmailAddress

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

the class ConvertLeadWizardService method createEmailAddress.

public EmailAddress createEmailAddress(String address, Lead lead, Partner partner) {
    EmailAddress emailAddress = new EmailAddress();
    emailAddress.setAddress(address);
    emailAddress.setLead(lead);
    emailAddress.setPartner(partner);
    return emailAddress;
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 14 with EmailAddress

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

the class OpportunityServiceImpl method createClientFromLead.

@Override
@Transactional(rollbackOn = { Exception.class })
public Partner createClientFromLead(Opportunity opportunity) throws AxelorException {
    Lead lead = opportunity.getLead();
    if (lead == null) {
        throw new AxelorException(opportunity, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAD_PARTNER));
    }
    String name = lead.getFullName();
    Address address = null;
    if (lead.getPrimaryAddress() != null) {
        // avoids printing 'null'
        String addressL6 = lead.getPrimaryPostalCode() == null ? "" : lead.getPrimaryPostalCode() + " ";
        addressL6 += lead.getPrimaryCity() == null ? "" : lead.getPrimaryCity().getName();
        address = addressService.createAddress(null, null, lead.getPrimaryAddress(), null, addressL6, lead.getPrimaryCountry());
        address.setFullName(addressService.computeFullName(address));
    }
    EmailAddress email = null;
    if (lead.getEmailAddress() != null) {
        email = new EmailAddress(lead.getEmailAddress().getAddress());
    }
    Partner partner = Beans.get(PartnerService.class).createPartner(name, null, lead.getFixedPhone(), lead.getMobilePhone(), email, opportunity.getCurrency(), address, address, true);
    opportunity.setPartner(partner);
    opportunityRepo.save(opportunity);
    return partner;
}
Also used : AxelorException(com.axelor.exception.AxelorException) EmailAddress(com.axelor.apps.message.db.EmailAddress) Address(com.axelor.apps.base.db.Address) Lead(com.axelor.apps.crm.db.Lead) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) EmailAddress(com.axelor.apps.message.db.EmailAddress) Transactional(com.google.inject.persist.Transactional)

Example 15 with EmailAddress

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

the class DMSFileServiceImpl method sendEmail.

@Override
public void sendEmail(DMSFile dmsFile) throws AxelorException, MessagingException {
    final EmailAccount emailAccount = mailAccountService.getDefaultSender();
    User currentUser = AuthUtils.getUser();
    User lockedBy = dmsFile.getLockedBy();
    EmailAddress emailAddress = this.getEmailAddress(lockedBy);
    String content = null;
    String language = currentUser.getLanguage();
    if (language != null && language.equals("fr")) {
        content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
    } else {
        content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
    }
    List<EmailAddress> toEmailAddressList = new ArrayList<>();
    toEmailAddressList.add(emailAddress);
    Message message = messageService.createMessage(null, 0, I18n.get(SUBJECT), content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, emailAccount, null);
    messageService.sendByEmail(message);
}
Also used : EmailAccount(com.axelor.apps.message.db.EmailAccount) User(com.axelor.auth.db.User) IExceptionMessage(com.axelor.apps.projectdms.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) ArrayList(java.util.ArrayList) 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