Select random email address from Excel sheet and then email that customer (Raffle)

Hello

New RPA developer here with very limited experience.

I have a list of records in Excel, each record has an email address. I want to select 1 email address from Excel randomly and then email this user.

I have a workflow that reads all records in an Excel file and then emails all users that have an email address.

How could I adapt this automation?

Please note I don’t have a data table as I can’t get it to work correctly.

Any tips here are greatly appreciated. If you know of a recent video where this is shown can you please reply, I have some other videos from 3 and 4 years ago, but there are differences in studio that I haven’t been able to resolve.

Cheers

Hie @fee3f91749a34c0c00102720d use read range workbook to read the dt and save it into a variable let’s say dt1
use for each row activity to iterate data one by one
inside this use if condition - and inside if use currentrow("column Name).tostring.equals("xyz.gmail.com)if it true or match
then inside then branch use send mail activity
cheers Happy Automation

@fee3f91749a34c0c00102720d,

To achieve your goal of selecting a random email address from an Excel file and sending an email to that user using UiPath Studio, you can follow these steps:

  1. Read the Excel file to get the list of email addresses.
  2. Select a random email address from the list.
  3. Send an email to the selected email address.

Here’s a step-by-step guide to help you build this automation:

Step 1: Read the Excel File

  1. Add the Excel Application Scope activity to open your Excel file.
  • Set the FilePath property to the path of your Excel file.
  1. Use the Read Range activity to read the data from the Excel file into a DataTable.
  • In the Read Range activity, set the SheetName and Range properties as needed.
  • Store the output in a variable, e.g., dtEmails.

Step 2: Select a Random Email Address

  1. Get the Row Count of the DataTable to determine the number of email addresses.
  • Use the Assign activity: rowCount = dtEmails.Rows.Count
  1. Generate a Random Index to select a random email address.
  • Use the Assign activity to create a random number: randomIndex = New Random().Next(0, rowCount)
  1. Get the Email Address at the random index.
  • Use the Assign activity to extract the email address: selectedEmail = dtEmails.Rows(randomIndex)("EmailAddress").ToString

Step 3: Send an Email

  1. Add the Send Outlook Mail Message activity (or the appropriate mail activity for your email service).
  • Set the To property to selectedEmail.
  • Set the Subject and Body properties as needed.

LLM helped me to write this but validated by me

Thanks,
Ashok :slight_smile:

@fee3f91749a34c0c00102720d

Add a Read Range activity store the excel data into a datatable
Let say your datatable name is dtEmails

randomIndex = CInt(Math.Floor(Rnd() * dtEmails.Rows.Count))
selectedEmail = dtEmails.Rows(randomIndex)("EmailColumnName").ToString()

Hope this will help you

Hi @fee3f91749a34c0c00102720d

 <Assign To="rowCount" Value="emailDataTable.Rows.Count" />
    <Assign To="randomIndex" Value="New Random().Next(0, rowCount)" />
    <Assign To="selectedEmail" Value="emailDataTable.Rows(randomIndex)("EmailColumnName").ToString" />

Hope it helps!!

Hi,

Could you provide the full workflow, I am still not getting it to work here

Cheers

Appreciate this

@fee3f91749a34c0c00102720d

Find the Zip file
Forum.zip (46.6 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.