Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

How to send excel sheet attachment mail through AL code

(0) ShareShare
ReportReport
Posted on by 153
Hi Guys,
I want automatically to send excel sheet through mail.
I have one excel sheet. & this sheet is created through excel buffer. i want to send mail this sheet through AL code.
Please let me know Is any way to do this. 
For example: In below image. I have one mail recipient's field. i want to send mail this recipient.
 
  • Suggested answer
    Nilam Bhor Profile Picture
    Nilam Bhor 153 on at
    How to send excel sheet attachment mail through AL code
    ,
     
     
     
     
    I am using below your code,but getting this error.
  • Janarthananv Profile Picture
    Janarthananv 87 on at
    How to send excel sheet attachment mail through AL code
    Dear  Nilam bhor,
     
    Please call the function in the button or code unit. This code is working for us. Please give a try and let us know
     
    Please use the given below
     
     local procedure Email()
        var
            Email: Codeunit Email;
            EmailMessage: Codeunit "Email Message";
            TempBlob: Codeunit "Temp Blob";
            ReportParameters: Text;
            EmailBody: Text[100];
            Subject: Text[100];
            Recipient: Text[1000];
            InStr: Instream;
            OutStr: OutStream;
            ReportValves: Text[100];
        begin
            EmailBody := 'Dear Team, ';
            EmailBody += 'Please find attached the reports as of ';
            Subject := 'Sample Subject';
            ReportValves := 'Sample Report';
            ReportValves += '.xlsx';
            Recipient := 'Test@gmail.com';
            EmailMessage.Create(Recipient, Subject, EmailBody);
            TempBlob.CreateOutStream(OutStr);
            TempBlob.CreateInStream(InStr);
            Report.SaveAs(Report::"Standard Sales - Invoice", ReportParameters, ReportFormat::Excel, OutStr);
            EmailMessage.AddAttachment(ReportValves, 'Excel', InStr);
            Email.Send(EmailMessage, Enum::"Email Scenario"::Default);
        end;
     
     
    Thanks
    Janarthanan v

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans