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...
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;
I have the same question (0)
  • Verified answer
    Tech-Lucky Profile Picture
    1,261 Super User 2025 Season 2 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 

  • 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

  • Suggested answer
    Tech-Lucky Profile Picture
    1,261 Super User 2025 Season 2 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

    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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,568

#2
Sumit Singh Profile Picture

Sumit Singh 2,536

#3
YUN ZHU Profile Picture

YUN ZHU 2,015 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans