Skip to Content
Technical Articles
Author's profile photo Jerome GRONDIN

SAP Intelligent RPA 2.0 : How to send multiple attachments in a mail

Playing a bit with the Outlook SDK in SAP Intelligent RPA 2.0, I realized that there was no direct way to add multiple files as attachments in a mail. I mean, yes there is one, but to be able to use that, you need to know in advance how many files will be attached to the mail.

But what if you only know this number at the runtime execution ?

 

Well, in that case, you came to the right place : here !

 

Context

Let’s assume the bot you’re building needs to send an email. That, you already know how to do it.

But if the attachments are dynamic (i.e. the list of attached files might be different depending on some variables in the flow), things can become a little more complicated. So let me show you how to proceed.

In the following, I’ll assume that you know how to import and use the Outlook SDK in your Cloud Studio project (especially with the use of Open Outlook activity, etc.). Otherwise, do not hesitate to have a look at the Learning samples on the Store, the different articles in the Help Portal, and of course multiple blog posts about it.

 

Design of the bot

Let’s have a look at the activity Send Email (Outlook).

My first question : What is the type of the input parameter ?

Hey genius, that’s an easy one. It is an Email Parameter.

You’re right. So let’s use an Email Parameter variable. Now the Send Email activity should take this variable as input parameter.

 

Now if you look at it, the Email Parameters contains a field to attach files. Here :

More precisely, this field is a… list ! At this point, you should see what will come next. Still not ? Then allow me to enlighten you.

 

Second question : from the Outlook SDK perspective, what is an attachment ?

I know ! It’s a file !

Yes, but no. It is a string which is the path of the file to be sent. It is not the same. And working with list of strings, that we know how to do it !

So let’s create a list of strings in our automation.

 

From now it is your job to fill this list, with the path of the files the bot should send. This list can contain one single file, or a dozen. We do not care. We are working with the list itself, not the content of the list.

How can I attach the list to the Email Parameter ? The interface does not change.

You’re right, the UI will not change. But since we know the field is a list, and since we have created one, we can concatenate them. And that, dear bot builders, is something that can be done with another activity. See below :

With the Add All activity, you can add the paths of all files to the Email Parameter variable. Just start to type the name of the Email Parameter variable in the list parameter, and select the one ending with .Attachments

The listToConcatenate simply is the list you created.

And now, you have a dynamic list that can be sent by your bot.

 

So let’s sum up :

  1. Create a list of string
  2. Fill that list with the path of all files that should be attached in the mail (this can be done all along the automation
  3. Create an Email Parameter variable that will be used in the Send Email activity
  4. Concatenate the list of string to the attachments of the Email Parameter variable
  5. Send the mail

 

NB: It is also possible to use the Add Item activity to directly add a string to the Attachments list in Email Parameter. You can do it inside a loop, or multiple times in your automation. Result would be the same

 

Conclusion

Given some situations, we might not be able to solve our issues directly. But this can always be done when we closely look at the types of objects used by the bot. In our case, the Email Parameter, and the list of strings.

 

Do not forget to have a look at the Learning content in our Store, as it contains many other examples of use cases like this one.

 

Find more information on SAP Intelligent RPA:

Exchange knowledge: SAP Community | Q&A | Blog

Learn more: Webinars | Help Portal | openSAP

Explore: Product Information | Successful Use Cases

Try SAP Intelligent RPA for Free: Trial Version | Pre-built Bots

Follow us on: LinkedInTwitter and YouTube

 

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.