Group results by contact column in datatable & send e-mails according to results

Hello,

We have a new process which queries the database for orders relating to clients and customers. Bulk e-mails are required to be sent at the start of the week, with orders that have been placed up to 6 days before.

The database results look like below:

OrderNumber | DeliveryDate | contactEmailAddress
123 12/02/2020 test1@test.com
456 24/02/2020 test2@test.com
789 28/02/2020 test1@test.com
1011 01/03/2020 test2@test.com

i’m trying to somehow group & split the results of the datatable by e-mail address, so that the the order details are sent in bulk to each contactEmailAddress (rather than sending an e-mail for each order).

For example:

To: test1@test.com
From: Bot@robot.com

Your recent orders are as follows:
OrderNumber | DeliveryDate |
123 12/02/2020
789 28/02/2020


To: test2@test.com
From: Bot@robot.com

Your recent orders are as follows:
OrderNumber | DeliveryDate |
456 24/02/2020
1011 01/03/2020

I cannot get me head around how group the results for each unique e-mail address & somehow dynamically create a datatable to hold the results (for me to use in the body of an e-mail).

Any suggestions?
Thanks in advance!

Filter based on the mail id and store it in separate datatable.

Then send mail to respective mail with all correspoding data

Sample :-
(from line in dt.select where line.contactEmailAddress.equals(“test1@test.com”) select line)

This will return rows with test1@test.com.

After u extract for all the mail IDs.

U can loop and send mail to respective mails with corresponding data

Hi,
Thanks for your reply @karthick .

Could you provide some more info around this solution?
I can’t seem to picture it in my head…

Thanks

Would you be able so provide a test file for me to work with?
I’d really appreciate it!

@arivu96 apologies, but do you have any ideas for this?

Hi @qwerty1,

Get distinct of email first.
Then do for each in the loop you filter the email from the main table.

Regards,
Arivu

1st step to filter the distinct email
DataTable dtdistinct=DataTableMain.DefaultView.ToTable(true,"contactEmailAddress")

2.use for each of dtdistinct table

Inside loop again filter to get the all the values based on distinct mail.

DataTable dtdistinctmail=DataTableMain.Select("contactEmailAddress='"+row("contactEmailAddress").ToString+"'").CopyToDataTable()

Regards,
Arivu

1 Like

Fantastic!
Thanks @arivu96 very much appreciated!

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