How can I efficiently add emails to a queue in UiPath—with sender, subject (as unique reference), and attachments—while minimizing processing time?

Hello UiPath Community,

I’m currently working on an Email Automation project where I need to upload incoming emails to an Orchestrator Queue. Specifically, for each email, I want to store the following information:

Subject(to be used as a unique reference)
Sender(which is constant)
Email Body
Attachments(either saved or base64 encoded)

To ensure queue integrity, I’m using the Subject as the Unique Reference field for each queue item.

However, I’m trying to achieve this in the most time-efficient way possible, ideally without using a For Each loop to iterate through each email individually. Since the sender is constant, I would like to upload all relevant emails in a single operation or using a more optimized method that minimizes execution time.

My key questions are:

  1. Is there any way to upload multiple emails (including attachments and metadata) to a queue without iterating through each one using a For Each loop?
  2. Can Bulk Add Queue Items be used in this case with MailMessage objects, or do we need to convert the data into a DataTable or a list of dictionaries first?
  3. Are there any external packages or custom activities available that can handle this operation more efficiently?
  4. Since the sender is always the same, can this be factored in to reduce processing logic?
  5. Has anyone implemented a similar approach with a focus on performance and low runtime latency?

You can use LINQ to convert List of MailMessage to Data table and then you can use Bulk Add Queue Items

Example code-

C#:
DataTable dt = messages
.Select(m => new {
Sender = m.From?.Address ?? string.Empty,
Body = m.Body ?? string.Empty,
Attachments = string.Join(“###”, m.Attachments.Cast().Select(a => a.Name))
})
.CopyToDataTable()

Dim dt As DataTable = messages _
.Select(Function(m) New With {
.Sender = If(m.From?.Address, String.Empty),
.Body = If(m.Body, String.Empty),
.Attachments = String.Join(“###”, m.Attachments.Cast(Of Attachment)().Select(Function(a) a.Name))
}) _
.CopyToDataTable()

@Vikas_b_Sajjan,

Bulk Add Queue Items does not take MailMessage directly, as I think the easiest solution is to convert email details into a DataTable or list of dictionaries and then push all items at once. Use Subject as Reference, put Body in SpecificContent, save or encode attachments before adding, and sender can be added as a fixed field to reduce logic. This avoids looping and gives best performance.

@Vikas_b_Sajjan

Few security considerations and limitations here

  1. First thing queue does not support attachments etc
  2. Saving full main data might not be needed and also exposes the data
  3. Better way would be to loop through emails and add the message id which is unique for each mail..and in performer you can retreive all the data you need by using get mail by if activity and message id in queue. Also bulk add can be used ..by adding all message ids to dt and then use bulk add

Cheers

1 Like

Hi @Anil_G

Can you please explain 3rd point Better way would be to loop through emails and add the message id which is unique for each mail..and in performer you can retreive all the data you need by using get mail by if activity and message id in queue. Also bulk add can be used ..by adding all message ids to dt and then use bulk add

how to provide unique message id

@Sushma_Ganapatisa

From the mailmessage object you will have id already..

Mailmessagevariable.MessageID will give th message id

Alternately in header or email also u
You would have id

Cheers

Use the intergation process to monitor the mailbox,

1 Like

couldn’t get message ID

@Sushma_Ganapatisa

What youa re trying on is full list..when you loop on list for eqch email then you will get id for each email..

So first add loop add mailmessages as input and isnide it you will get individual mailmessage items

Cheers

I tried with the loop current mail, but wasn’t able to get the message ID

@Sushma_Ganapatisa

As said depending on what you use ..as you are using outlook header is where you get it

mailmessages(0).Headers("Message-ID")

Also as @rmorgan suggested instead of adding to queue you can setup integrations ervice trigger as well which will trigger process based on subject you need when its received

cheers