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

Send Email With Attachment in NAV 2013 r2

(0) ShareShare
ReportReport
Posted on by 30

While running codeunit its sending all customer statement as pdf .not only specific customer.

if i use setrange filter 1img error come.

with filter sending email with all customer report not specific.

thikasetrangeerror.pngthikaemailerror.png

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Send Email With Attachment in NAV 2013 r2

    Hello,

    You are exporting the Image to FileName and in the email Attachment you have used FilePath variable that's why you are not getting the attachment.

    ***I recommended you to sending email with attachment use the stream attachment.

    I have used the stream as shown below and it works, Stream will increase the performance because you do not required additional tasks

    like inserting in temp blob and exporting again.

    LOCAL SendMailWithAttachment() //function name
    //>>BKS 07.18.20
    T409.GET;
    WITH CU400 DO BEGIN
      CreateMessage(
                'Auto Service',
                T409."User ID",           //Sender Address
                T409."Test Mail ID",      //Recipients Address
                STRSUBSTNO(Sub, TODAY),   //Subject
                'Hello All,',
                TRUE
                );
      AppendBody('

    '); AppendBody(STRSUBSTNO('Please ignore the email as it was testing by %1.', USERID)); AppendBody('

    '); AppendBody('Regards,'); AppendBody('
    '); AppendBody('Auto Service'); AppendBody('

    '); AppendBody('
    '); AppendBody('This is a system generated mail. Please do not reply to this mail id'); //Attachment CompanyInformation.GET; CompanyInformation.CALCFIELDS(Picture); IF CompanyInformation.Picture.HASVALUE THEN BEGIN CompanyInformation.Picture.CREATEINSTREAM(PicInStream); AddAttachmentStream(PicInStream,'Company Picture.png'); END; Send; END; //<

    pastedimage1595059467656v1.png

  • AbhishekJungwal Profile Picture
    AbhishekJungwal 30 on at
    RE: Send Email With Attachment in NAV 2013 r2

    althika-imageserror.png

    i use this code for send company logo in email but its send blank image plzhelp

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Send Email With Attachment in NAV 2013 r2

    Hello Abhishek,

    See the below code for your reference, this code is working for me.

    SendCSMail is a function with simple code which will send email for each customer.

    if you are using Report 116 then use filter as per your report, I have used Report 10072.

    CustomerStatement.InitializeRequest is a custom function to initialize the request page of the report.

    LOCAL SendCustomerStmt()
    WITH CustomerG DO BEGIN
      RESET;
      SETFILTER("No.", '3|100|100182|100676'); Customer number filters
      SETRANGE(Blocked, Blocked::" ");
      NewPrintEntriesDue := TRUE;
      NewPrintAllHavingBal := TRUE;
      NewPrintCompany := TRUE;
      NewPrintRemitTo := TRUE;
      NewUpdateNumbers := TRUE;
      NewStatementStyle := NewStatementStyle::"Open Item";
      NewAgingMethod := NewAgingMethod::"Trans Date";
      NewStartDate := CALCDATE('-CM',TODAY);
      EVALUATE(NewPeriodCalculation, '');
      IF FINDSET THEN BEGIN
        REPEAT
          CustomerL.RESET;
          CustomerL.SETRANGE("No.", "No.");
          CustomerL.FINDFIRST;
          CLEAR(CustomerStatement); //Report 10072
          CLEAR(FileNameL);
          CustomerStatement.SETTABLEVIEW(CustomerL);
          CustomerStatement.USEREQUESTPAGE(FALSE);
          CustomerStatement.InitializeRequest(
                                            NewPrintEntriesDue, NewPrintAllHavingEntry,
                                            NewPrintAllHavingBal, NewUpdateNumbers,
                                            NewPrintCompany, NewPrintRemitTo,
                                            NewStatementStyle, NewAgingMethod,
                                            NewPeriodCalculation, NewLogInteraction,
                                            NewChosenOutputMethod, NewPrintRemaining, NewStartDate
                                            );
          
          AttachmentFileWithPath := Path   CustomerL."No."   '.pdf';    //Attachment File Name
          
          IF CustomerStatement.SAVEASPDF(AttachmentFileWithPath) THEN BEGIN
            IF FileManagement.ServerFileExists(AttachmentFileWithPath) THEN BEGIN
              IF NOT RemoveEmptyFile(AttachmentFileWithPath) THEN
                SendCSMail(AttachmentFileWithPath, ToAddressL, CS_Subject);
            END;
          END;
        UNTIL NEXT = 0;
      END;
    END;

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans