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);
}
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[]
}
}
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);
}
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();
}
}
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;
}
Aggregations