Send Mass Email to Customer

Send Mass Email to Customer

Hi Everyone!
I have a portal customer and i want to send a mass email when i import some data on a form.
The data cointains number that are related with pay invoices. For example:



This NumDoc is relate to some email customer, so when I import the csv, i need that send an email to the customer that indicates that the invoices was paid.

The currently code that i made is the below, but send me email by all the records.

rec_acc = Dream[Doctype == input.DocType && NumDoc == input.NumDoc];
rec_rut = Vendors[Account == rec_acc.ACC];
rec_invoice = Invoice_Tracker[Rut_Emisor == rec_rut.Rut && Folio_Dte == rec_acc.Folio];
for each  record in Pay_list
{
if(rec_acc.Doctype + "" + rec_acc.NumDoc == input.DocType + "" + input.NumDoc)
{
sendmail
[
from :zoho.adminuserid
to : rec_acc.email
subject :rec_invoice.Razon_Social
message :"Facturas Pagadas:" + rec_invoice.Folio_Dte
]
}
}



And the last question is how i can group the data for the customer?
I import a csv with 3 rows, the first 2 is for one customer, and the last is for another, how i can separate the emails for that the first curstomer receive a email with 2 rows of data and the another customer receive the last row of data? is this possible with deluge?


I help that can u help me!!

Best Regards