Skip to main content

Notifications

Announcements

No record found.

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

AL - Change email body

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
    Diego91 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
    Tech-Lucky 796 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
    Diego91 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
    Tech-Lucky 796 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans