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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Issue with sending email

(0) ShareShare
ReportReport
Posted on by 50

I have tried to schedule a job in job queue for sending an email, But the mail does not send.

Here is mycode

codeunit 50101 MyCodeunit
{
    trigger OnRun()
    begin
        Salesperson.Reset();
        Salesperson.SetFilter("E-Mail", '<>%1', '');
        If Salesperson.FindSet() then
            repeat
                RecSalesInv.Reset();
                RecSalesInv.SetRange("Salesperson Code", Salesperson.Code);
                RecSalesInv.SetRange("Posting Date", WorkDate());
                if RecSalesInv.FindSet() then
                    if RecSalesInv.Count > 0 then
                        Smail(RecSalesInv.Count, "Salesperson"."E-Mail", RecSalesInv);
            until Salesperson.Next() = 0
    end;


    procedure Smail(InvCount: Integer; SentTo: Text; var RecSalesInv_p: Record "Sales Invoice Header")
    var
        TemplineMail: Record "Email Item" temporary;
        TemplineScanario: Enum "Email Scenario";
        SubjectTxt: Label 'Daily invoice report';

        BodyTxt: Label 'Dear %1, <br><br> You have a posted %2 invoices on %3 <br><br><b>Total Invoice Amount :</b> %4 .<br> Please find the details below<br><br>';
        StyleText: Text;
        HeaderTxt: Text;
        coText: Text;
        EndText: Text;
        TableText: Text;
        TotalText: Text;
        TotalInvoiceAmount: Decimal;
    begin
        TemplineMail.Initialize();
        TemplineMail.Subject := SubjectTxt;
        RecSalesInv_p.SetAutoCalcFields("Amount Including VAT");
       

       
        StyleText := '<style>table, th, td {border:1px solid black;}</style>';
        HeaderTxt := '<table><b><tr><th>Document No.</th><th>Customer Name</th><th>Total Amount</th></b></tr>';
        TableText := '';
        TotalText := '';
        TotalInvoiceAmount := 0;
        If RecSalesInv_p.FindSet() then
            repeat
                TableText := '<tr><td>' + RecSalesInv_p."No." + '</td><td>' + RecSalesInv_p."Sell-to Customer Name" + '</td><td>' + Format(RecSalesInv_p."Amount Including VAT") + '</td></tr>';
                TotalText += TableText;
                TotalInvoiceAmount := TotalInvoiceAmount + RecSalesInv_p."Amount Including VAT";
            until RecSalesInv_p.Next() = 0;
        EndText := '</table> <br><br>Regards,<br><br>' + CompanyName;
       
        TemplineMail.SetBodyText(coText + StyleText + HeaderTxt + TotalText + EndText);
        TemplineMail."Send to" := SentTo;
        TemplineMail.SendAsHTML(true);
        TemplineMail.Send(true, TemplineScanario::Default);
        Sleep(1000);
    end;

    var
        myInt: Integer;
        RecSalesInv: Record "Sales Invoice Header";
        Salesperson: Record "Salesperson/Purchaser";
}
  • venkadachalam Profile Picture
    50 on at

    In Job Queue Entries, When I tried runsonce(foreground), the mail was sent. But while schedule a job, the mail does not send.

    Please advice

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Did you setup the Jop queue scheduling with No. of minutes. see below

    pastedimage1669215059363v1.png

  • venkadachalam Profile Picture
    50 on at

    Thank you for your reply,

    I tried using No of minute between runs, but the mail does not send.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 753 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 583 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 302 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans