I am iterating using For Each through an excel to Extract some report using SAP and Excel. I have a list of items and their respective emails in an excel. The names are repetitive but I want the mail to be sent only once to any person even if their email id is getting repeated.
I have Included SendEmail workflow in For Each loop itself, so if i use CurrentRow(email).tostring, multiple emails are sent about every item. I do not want that . Please suggest
->Read the Excel using read range workbook and store in a data table.
→ Filter the data table to get Unique Emails
for eg: dtUniqueEmails = dt.DefaultView.ToTable(True, “EmailColumn”)
→ Use For Each Row and Loop Through Unique Emails
→ Inside the loop, use the Send Email activity to send emails to the corresponding email addresses.
->Create an empty list “EmailList” before iterating through for each loop.
→ Inside the loop use an “If” condition to check if the current row’s email address is already in the “EmailList” column or not.
Use “EmailList.Contains(CurrentRow(“email”).ToString)” condition to check for duplicates.
->If the email address is not present in the “EmailList”, then send an email using the “Send Outlook Mail Message” activity, passing the current row’s email address as the recipient.
After sending the email, add the email address to the “EmailList” using the “EmailList.Add(CurrentRow(“email”).ToString)” statement.
You can also refer the steps below:
Assign EmailList = New List(Of String)
For Each Row in data
If Not EmailList.Contains(row(“email”).ToString)
Send Outlook Mail Message (or any other email activity) (set the recipient email address using row(“email”).ToString)