Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

AL - Change email body

(0) ShareShare
ReportReport
Posted on by 25

Hi Everyone,

I try to send an email with an attached document, this code works very well, but I need to write a specific text for each email, for now the body arrives empty, does anyone know how to modify it?
thank you so much

//My code

var
                SalesInvoiceHeader: record "Sales Invoice Header";
                DocumentSendingProfile: Record "Document Sending Profile";
                DummyReportSelections: Record "Report Selections";
                Text2: text;

                SalesInvoiceHeader.RESET();
                SalesInvoiceHeader.SetRange("No.", "No.");
                if SalesInvoiceHeader.FindSet() THEN begin

            
                    DocumentSendingProfile.TrySendToEMail(
                    DummyReportSelections.Usage::"S.Invoice".AsInteger(), SalesInvoiceHeader, 100, Text2,
                    4, false);
                    exit;




                end;
  • Diego91 Profile Picture
    25 on at
    RE: AL - Change email body

    Hello Tech, I solved it in another way using a temporary table before sending the mail, and adding a procedure inside the event subscription, I have solved the problem, thank you very much for your help

    greetings

  • Suggested answer
    Tech-Lucky Profile Picture
    935 on at
    RE: AL - Change email body

    for that, you need to customize it more , you can subscribe OnBeforeSendEmail event as shown in the below image and exit the standard code it has the PostedDoc No as a parameter you can use it and re-write the Standard code on your custom code for further process then you can directly modify the body as well without subscribing the previous event that I told you.

    this is the Function EmailFileInternal in Codeunit "Document-Mailing" You can explore more for a much better solution I just explained one of the possibilities.

  • Diego91 Profile Picture
    25 on at
    RE: AL - Change email body

    Hi tech, thanks, this works, but I need to add details of the Sales Invoice Header record to the body of the email. I don't see in that event that I receive the record as a parameter. Do you know how I can map it from the subscription?

    thank you so much

  • Verified answer
    Tech-Lucky Profile Picture
    935 on at
    RE: AL - Change email body

    You need to use the Event to modify the Email Body as bellow : 

        [EventSubscriber(ObjectType::Table, database::"Email Item", 'OnBeforeGetBodyText', '', false, false)]
        local procedure OnBeforeGetBodyText(var EmailItem: Record "Email Item"; var Value: Text; var IsHandled: Boolean)
        begin
            IsHandled := true;
            //Write your custom email Body here 
            value := 'Please Find the attched Invoice'; // this is just an example
        end;

    But I tried your code and that does not send the email with the empty body the default body is quite good you can see the screenshot : 

    DP2.jpg

    after using the event I modified the body and received the mail as bellow : 

    I hope this helps you if YES please verify this answer 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,351 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,029 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans