Search in sources :

Example 1 with EmailInfo

use of io.jmix.email.EmailInfo in project jmix-docs by Haulmont.

the class SendEmailJavaDelegate method execute.

@Override
public void execute(DelegateExecution execution) {
    // <2>
    // <3>
    User addresseeValue = (User) addressee.getValue(execution);
    String emailSubjectValue = (String) emailSubject.getValue(execution);
    String emailBodyValue = (String) emailBody.getValue(execution);
    EmailInfo emailInfo = // <4>
    EmailInfoBuilder.create().setAddresses(addresseeValue.getEmail()).setSubject(emailSubjectValue).setFrom(null).setBody(emailBodyValue).build();
    // <5>
    emailer.sendEmailAsync(emailInfo);
}
Also used : User(bpm.ex1.entity.User) EmailInfo(io.jmix.email.EmailInfo)

Example 2 with EmailInfo

use of io.jmix.email.EmailInfo in project jmix-docs by Haulmont.

the class TaskAssignedNotificationSender method onOtherProcessTaskAssigned.

// end::event-listener-1[]
// tag::specific-process-1[]
@EventListener
protected void onOtherProcessTaskAssigned(UserTaskAssignedEvent event) {
    if ("order-approval".equals(event.getProcessDefinition().getKey())) {
        // ...
        // end::specific-process-1[]
        User user = dataManager.load(User.class).query("select u from smpl_User u where u.username = " + ":username").parameter("username", event.getUsername()).one();
        Task task = event.getTask();
        String emailTitle = "New process task " + task.getName();
        String emailBody = "Hi " + user.getFirstName() + "\n" + "The task" + task.getName() + "has been assigned.";
        EmailInfo emailInfo = EmailInfoBuilder.create().setAddresses(user.getEmail()).setSubject(emailTitle).setFrom(null).setBody(emailBody).build();
        emailer.sendEmailAsync(emailInfo);
    // tag::specific-process-2[]
    }
}
Also used : Task(org.flowable.task.api.Task) User(bpm.ex1.entity.User) EmailInfo(io.jmix.email.EmailInfo) EventListener(org.springframework.context.event.EventListener)

Example 3 with EmailInfo

use of io.jmix.email.EmailInfo in project jmix-docs by Haulmont.

the class TaskAssignedNotificationSender method onTaskAssigned.

// <1>
@EventListener
public void onTaskAssigned(UserTaskAssignedEvent event) {
    // <2>
    User user = // <3>
    dataManager.load(User.class).query("select u from smpl_User u where u.username = :username").parameter("username", event.getUsername()).one();
    // <4>
    Task task = event.getTask();
    String emailTitle = "New process task " + task.getName();
    String emailBody = "Hi " + user.getFirstName() + "\n" + "The task " + task.getName() + " has been assigned.";
    EmailInfo emailInfo = EmailInfoBuilder.create().setAddresses(user.getEmail()).setSubject(emailTitle).setFrom(null).setBody(emailBody).build();
    // <5>
    emailer.sendEmailAsync(emailInfo);
}
Also used : Task(org.flowable.task.api.Task) User(bpm.ex1.entity.User) EmailInfo(io.jmix.email.EmailInfo) EventListener(org.springframework.context.event.EventListener)

Example 4 with EmailInfo

use of io.jmix.email.EmailInfo in project jmix by jmix-framework.

the class EmailTemplateSendScreen method onSendButtonClick.

@Subscribe("sendButton")
public void onSendButtonClick(Button.ClickEvent e) throws TemplateNotFoundException, ReportParameterTypeChangedException {
    if (!validateAll()) {
        return;
    }
    if (BooleanUtils.isNotTrue(emailTemplate.getUseReportSubject()) && subjectField.getValue() == null) {
        notifications.create(Notifications.NotificationType.WARNING).withDescription(messages.getMessage(EmailTemplateSendScreen.class, "emptySubject")).show();
        return;
    }
    EmailInfo emailInfo = getEmailInfo();
    try {
        emailer.sendEmail(emailInfo);
        notifications.create(Notifications.NotificationType.HUMANIZED).withDescription(messages.getMessage(EmailTemplateSendScreen.class, "emailSent")).show();
        close(WINDOW_COMMIT_AND_CLOSE_ACTION);
    } catch (EmailException exception) {
        notifications.create(Notifications.NotificationType.ERROR).withDescription(StringUtils.join(exception.getMessages(), "\n")).show();
    }
}
Also used : EmailException(io.jmix.email.EmailException) EmailInfo(io.jmix.email.EmailInfo)

Example 5 with EmailInfo

use of io.jmix.email.EmailInfo in project jmix by jmix-framework.

the class EmailTemplatesImpl method generateEmail.

@Override
public EmailInfo generateEmail(EmailTemplate emailTemplate, Collection<ReportWithParams> params) throws TemplateNotFoundException, ReportParameterTypeChangedException {
    if (emailTemplate == null) {
        throw new TemplateNotFoundException(messages.getMessage(EmailTemplates.class, "nullTemplate"));
    }
    List<ReportWithParams> parameters = new ArrayList<>(params);
    TemplateReport bodyReport = emailTemplate.getEmailBodyReport();
    ReportWithParams bodyReportWithParams = bodyReport != null ? getReportWithParams(bodyReport, parameters) : null;
    Map<TemplateReport, ReportWithParams> attachmentsWithParams = new HashMap<>();
    List<TemplateReport> attachedTemplateReports = emailTemplate.getAttachedTemplateReports();
    if (attachedTemplateReports != null) {
        for (TemplateReport templateReport : attachedTemplateReports) {
            ReportWithParams reportWithParams = getReportWithParams(templateReport, parameters);
            attachmentsWithParams.put(templateReport, reportWithParams);
        }
    }
    EmailInfo emailInfo = generateEmailInfoWithoutAttachments(bodyReportWithParams);
    List<EmailAttachment> templateAttachments = new ArrayList<>();
    templateAttachments.addAll(createReportAttachments(attachmentsWithParams));
    templateAttachments.addAll(createFilesAttachments(emailTemplate.getAttachedFiles()));
    emailInfo.setSubject(Boolean.TRUE.equals(emailTemplate.getUseReportSubject()) ? emailInfo.getSubject() : emailTemplate.getSubject());
    emailInfo.setAddresses(emailTemplate.getTo());
    emailInfo.setCc(emailTemplate.getCc());
    emailInfo.setBcc(emailTemplate.getBcc());
    emailInfo.setFrom(emailTemplate.getFrom());
    emailInfo.setAttachments(templateAttachments);
    return emailInfo;
}
Also used : ReportWithParams(io.jmix.emailtemplates.dto.ReportWithParams) EmailAttachment(io.jmix.email.EmailAttachment) EmailTemplates(io.jmix.emailtemplates.EmailTemplates) TemplateNotFoundException(io.jmix.emailtemplates.exception.TemplateNotFoundException) EmailInfo(io.jmix.email.EmailInfo)

Aggregations

EmailInfo (io.jmix.email.EmailInfo)9 User (bpm.ex1.entity.User)5 Task (org.flowable.task.api.Task)4 EventListener (org.springframework.context.event.EventListener)4 EmailAttachment (io.jmix.email.EmailAttachment)2 Order (bpm.ex1.entity.Order)1 EmailException (io.jmix.email.EmailException)1 EmailTemplates (io.jmix.emailtemplates.EmailTemplates)1 ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)1 TemplateNotFoundException (io.jmix.emailtemplates.exception.TemplateNotFoundException)1 ByteArrayDataProvider (io.jmix.ui.download.ByteArrayDataProvider)1