Hello! I have a list of files. How can I send all files in that list as attachments using the E-Mail Step? The E-Mail Step allows me only to define a known number of attachments. Or is there another way to send a E-Mail with a variable number of attachments?

asked 23.01.2015 at 15:01

Peter%20Weber's gravatar image

Peter Weber
accept rate: 0%

Currently it is not possible to define a list directly in the Mail-Step.

As a workaround a predefined number of attachments can be added while using a simple macro. The macro gets the corresponding entry from the list, if it exists, or it returns an empty string.

  • The macro for the first line is: <%=(in.files.size() > 0) ? in.files.get(0) : ""%>
  • The macro for the second line is: <%=(in.files.size() > 1) ? in.files.get(1) : ""%>

The configuration of the E-Mail Step could look like this print screen:

E-Mail Step configuration with nearly variable list of attachments


answered 26.01.2015 at 09:56

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
accept rate: 75%

Yes, it works, but produces warnings for each line where the makro results in an empty string: WARNING: Email attachment: <%=(in.files.size() > 3) ? in.files.get(3) : ""%> is skipped, because it resulted an empty resource name.

(27.01.2015 at 15:41) Peter Weber Peter%20Weber's gravatar image

You can send mails from a script step with this java class.

import java.io.File;
import java.util.Map;
import java.util.concurrent.Callable;

import org.eclipse.core.resources.IProject;

import ch.ivyteam.ivy.components.config.EmailConfiguration;
import ch.ivyteam.ivy.email.EmailSetupConfiguration;
import ch.ivyteam.ivy.email.EmailSetupProviderUtil;
import ch.ivyteam.ivy.email.SimpleMailSender;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.project.IIvyProject;
import ch.ivyteam.ivy.project.IvyProjectUtil;
import ch.ivyteam.ivy.workflow.WorkflowNavigationUtil;
import ch.ivyteam.log.Logger;
import ch.soreco.ivybpmelements.util.Admin;

 * Class to send emails from java code.
public class Mail {

  EmailConfiguration emailConfig;
  Map<String, File> attachmentFiles;

  public Mail
    (String subject, String from, String replyTo,
        String to, String cc, String bcc, String message,
        Map<String, File> attachmentFiles) throws Exception {
      this.emailConfig = new EmailConfiguration();

      this.attachmentFiles = attachmentFiles;

  public Mail(EmailConfiguration emailConfig, Map<String, File> attachmentFiles) throws Exception {
    send(emailConfig, attachmentFiles);

  public void send() throws Exception {
    send(emailConfig, attachmentFiles);

  private void send(final EmailConfiguration emailConfig,
      final Map<String, File> attachmentFiles) throws Exception {

    (new Admin<Void>())
        .execute(new Callable<Void>() {

          public Void call() throws Exception {
            IProject project = WorkflowNavigationUtil
            IIvyProject ivyProject = IvyProjectUtil
            EmailSetupConfiguration mailSetup = EmailSetupProviderUtil
            Logger runtimeLogger = Ivy.log();
            SimpleMailSender mailSender = new SimpleMailSender(attachmentFiles,
                emailConfig, runtimeLogger, mailSetup);
            return null;


And to execute the code as system user.

import java.util.concurrent.Callable;

import ch.ivyteam.ivy.server.ServerFactory;

 * Class to execute code as the ivy system user.
 * @param <T>
public class Admin<T> {

   * Exeute code as system user.
   * @param callable
   * @return
   * @throws Exception
  public T execute(Callable<T> callable) throws Exception {
    return ServerFactory.getServer().getSecurityManager().executeAsSystem(callable);


answered 11.03.2015 at 16:07

HaraldWeber's gravatar image

accept rate: 33%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 23.01.2015 at 15:01

Seen: 1,142 times

Last updated: 11.03.2015 at 16:07