web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

I want to mail those customer who have at least one record else not sent mail

(1) ShareShare
ReportReport
Posted on by 133

Hi all I need your help in this code o want to sent mail to those customer who have record if record is not available then mail will not sent , if record is found then mail will sent to the customer.

mention below is the code for sent mail to customer.

Documentation()

OnRun()

SentMailtoCust(CustNo : Code[20])

SMTPSetup.GET;

Customer.GET(CustNo);

   Customer.TESTFIELD("E-Mail");

   IF CustLedgEntry.fin

   SMTPMail.CreateMessage('',SMTPSetup."User ID",Customer."E-Mail",'Test1','',TRUE);

   IF SalesPerson."E-Mail"<>'' THEN

     SMTPMail.AddCC(SalesPerson."E-Mail");

       SMTPMail.AppendBody('Dear Sir / Madam,');

       SMTPMail.AppendBody('<br><br>');

       SMTPMail.AppendBody('Please find Pending Payments List.');

       SMTPMail.AppendBody('<br><Br>');

       SMTPMail.AppendBody('<table border="1">');

       SMTPMail.AppendBody('<tr>');

       SMTPMail.AppendBody('<th>Invoice No.</th>');

       SMTPMail.AppendBody('<th>Invoice Date</th>');

       SMTPMail.AppendBody('<th>Due Date</th>');

       SMTPMail.AppendBody('<th>Invoice Amount</th>');

       SMTPMail.AppendBody('<th>Balance Amount</th>');

       SMTPMail.AppendBody('</tr>');

       CustLedgEntry.SETCURRENTKEY("Customer No.",Open,Positive,"Due Date","Currency Code");

       CustLedgEntry.SETRANGE(CustLedgEntry."Customer No.",CustNo);

       CustLedgEntry.SETRANGE(Open,TRUE);

       CustLedgEntry.SETRANGE(CustLedgEntry."Document Type",CustLedgEntry."Document Type"::Invoice);

      IF CustLedgEntry.FINDFIRST THEN

       REPEAT

           CustLedgEntry.CALCFIELDS("Amount (LCY)");

           CustLedgEntry.CALCFIELDS("Remaining Amt. (LCY)");

           SMTPMail.AppendBody('<tr>');

           SMTPMail.AppendBody('<td>'+FORMAT(CustLedgEntry."Document No.")+'</td>');

           SMTPMail.AppendBody('<td>'+FORMAT(CustLedgEntry."Posting Date")+'</td>');

           SMTPMail.AppendBody('<td>'+FORMAT(CustLedgEntry."Due Date")+'</td>');

           SMTPMail.AppendBody('<td>'+FORMAT(CustLedgEntry."Amount (LCY)")+'</td>');

           SMTPMail.AppendBody('<td>'+FORMAT(CustLedgEntry."Remaining Amt. (LCY)")+'</td>');

           SMTPMail.AppendBody('</tr>');

     UNTIL(CustLedgEntry.NEXT=0);

       SMTPMail.AppendBody('</table>');

       SMTPMail.AppendBody('<br><br>');

       SMTPMail.AppendBody('Regards,');

       SMTPMail.AppendBody('<br>');

       SMTPMail.AppendBody('Ajay Pandey');

       SMTPMail.AppendBody('<br><br>');

       SMTPMail.AppendBody('<HR>');

       SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this email ID.');

SMTPMail.Send;

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans