I have tried to schedule a job in job queue for sending an email, But the mail does not send.
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";
}