Skip to main content

Notifications

Small and medium business | Business Central, N...
Unanswered

Help :How made Code unit compatible for AL for sending mail

Posted on by 221

Hi experts 

I have code unit from NAV 2016 which custom code unit .I used CAL to AL converter To get AL file .but now it showing all errors as many functionality,table ,CU related to mail depreciated  from NAV to BC. I am not getting how to move forward Any help will Really appreciated Thanks in Advance!
I have shared code unit Which Converted in AL  

codeunit 50001 "Send Mail"
{
    trigger OnRun()
    begin
    end;
    var
        SMTPMail: Codeunit "400";
        SMTPSetup: Record "409";
    procedure SendMailToCust(CustNo: Code[20])
    var
        Customer: Record 18;
        CustLedgEntry: Record 21;
        SalesPerson: Record 13;
    begin
        SMTPSetup.GET;
        Customer.GET(CustNo);
        Customer.TESTFIELD("E-Mail");   
        SMTPMail.CreateMessage(SMTPSetup."Email Sendor Name", SMTPSetup."Email Sendor Email",
                               Customer."E-Mail", 'Pending Payments', '', TRUE);

        SalesPerson.GET(Customer."Salesperson Code");
        IF SalesPerson."E-Mail" <> '' THEN
            SMTPMail.AddCC(SalesPerson."E-Mail");
        SMTPMail.AppendBody('Dear Sir / Madam,');
        SMTPMail.AppendBody('

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

'); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); 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(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); SMTPMail.AppendBody(''); UNTIL (CustLedgEntry.NEXT = 0); SMTPMail.AppendBody('
Invoice No.Invoice DateDue DateInvoice AmountBalance Amount
' FORMAT(CustLedgEntry."Document No.") '' FORMAT(CustLedgEntry."Posting Date") '' FORMAT(CustLedgEntry."Due Date") '' FORMAT(CustLedgEntry."Amount (LCY)") '' FORMAT(CustLedgEntry."Remaining Amt. (LCY)") '
'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('Regards,'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Admin'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this email ID.'); SMTPMail.Send; end; procedure SendTestMailtoCust(CNo: Code[20]) var Cust: Record Customer; begin Cust.GET(CNo); SMTPSetup.GET; SMTPMail.CreateMessage(SMTPSetup."Email Sendor Name", SMTPSetup."Email Sendor Email", Cust."E-Mail", 'Test Mail', 'This the the mail Body', TRUE); SMTPMail.Send; end; procedure SendMailToCustWithAttachment(CustNo: Code[20]) var Customer: Record Customer; CustLedgEntry: Record 21; SalesPerson: Record 13; // StatementINPDF: Codeunit "50000"; begin SMTPSetup.GET; Customer.GET(CustNo); Customer.TESTFIELD("E-Mail"); SMTPMail.CreateMessage(SMTPSetup."Email Sendor Name", SMTPSetup."Email Sendor Email", Customer."E-Mail", 'Sales Statistics', '', TRUE); SalesPerson.GET(Customer."Salesperson Code"); IF SalesPerson."E-Mail" <> '' THEN SMTPMail.AddCC(SalesPerson."E-Mail"); SMTPMail.AppendBody('Dear Sir / Madam,'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('Please find Attached Sales Statistics.'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('Regards,'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('Admin'); SMTPMail.AppendBody('

'); SMTPMail.AppendBody('
'); SMTPMail.AppendBody('This is a system generated mail. Please do not reply to this email ID.'); SMTPMail.AddAttachment(SMTPSetup."Path to Save Report", ''); SMTPMail.Send; end; }
[View:/cfs-file/__key/communityserver-discussions-components-files/758/SendMail.Codeunit.al:320:240

  • AJ-21080818-0 Profile Picture
    AJ-21080818-0 60 on at
    RE: Help :How made Code unit compatible for AL for sending mail

    Hi,

    There is Email and "Email Message" codeunits that can be used instead of your outdated codeunit.

    Below is a sample of simple email sending birthday message. Check their methods if you can append lines in the body.

    var

    Email: Codeunit Email;

    EmailMessage: Codeunit "Email Message";

    Subject:='Hello';

    ToRecipients:='johnsmith@abc.com';

    company:=ReportsCode.getcompname;

    Body:='Dear ' + 'John Smith, <br><br>' + 'On behalf of the company wish you very happy birthday! <br><br>'+ company+'<br> HR Department';

    EmailMessage.Create(ToRecipients,Subject, Body, true);

    Email.Send(EmailMessage);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans