web
You’re offline. This is a read only version of the page.
close
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...
Suggested Answer

Using "Email Item" Table directly to send custom mail

(0) ShareShare
ReportReport
Posted on by 425

Hello Team,

I am Using "Email Item" Table directly to send custom mail. I now need help to add attachment. I need to add a custom report in attachment.

Below is the code.

action(Send)
            {
                ApplicationArea = all;
                Promoted = true;
                trigger OnAction()
                var
                    EndLine: Char;
                    EndLine2: Char;

                begin
                    EndLine := 13;
                    EndLine2 := 10;
                    WITH TempEmailItem DO BEGIN
                      
                        "Send to" := 'xyz@gmailcom';
                        Subject := 'Purchase Order# ' ;
                        "Message Type" := "Message Type"::"Custom Message";
                        
                        CLEAR(Body);

                        Body.CREATEOUTSTREAM(BodyStream);

                       
                        BodyStream.WriteText('Dear Sir/Madam,' + FORMAT(EndLine+ FORMAT(EndLine2));
                        BodyStream.WriteText('');
                        BodyStream.WriteText('Please find attached Purchase Order# ');

                    
                        
                       // "Attachment File Path" := FileManagement.Magicpath();
                        //"Attachment Name" := 'PO Report.pdf';
                        Commit();
                       
                        CalcFields(Body);

                 
                        Commit();
                        Send(FALSE);
                        

                    end;
                end;

            }
I have the same question (0)
  • Suggested answer
    Sumit_Nandha Profile Picture
    160 on at

    Hello,

    Using Email Item Table is quite easy for sending mails. It has a very easy structure and nice error handling. However, has also some limitations. The biggest one is not possible to add an attachment when developing for the cloud, at least I was not able to do so. This is because in the table there is no function to add attachments other than specifying attachment path – and that is not possible for the cloud.

    To create an mail you can add a variable for the table – use it as a temporary. Then you need to fill the fields such as Send to, Send CC, Send BCC, Subject, and Body.

    The Body field is type Blob. Which allows, without any additional work, to add the body from the report. Simple save report to HTML using method SaveAs. The OutStream will contain an email body. In the end, you just need to run function Send which is in the table.

    Read this blog for more details

    http://www.mynavblog.com/2019/12/17/sending-mails-in-the-cloud/

  • Manish Ratan Profile Picture
    425 on at

    Thanks for Reply,

    Is there any other way to use it.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,917

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,161 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,025 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans