web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

how to send report to email after posting the purchase invoice

(0) ShareShare
ReportReport
Posted on by 231

Hello 

I am new to nav so please suggest some answers for how to send email to users after posting the purchase invoice 

Thanks in advance

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Do you have SMTP Mail Setup table, User Setup table and SMTP Mail codeunit ?

  • yoheswaran Profile Picture
    231 on at

    Thanks for the response

    I have those things

  • Suggested answer
    Community Member Profile Picture
    on at

    I use to send mails using that steps

    1. Create variables

    pastedimage1569486494361v1.png

    2.Create parameters

    pastedimage1569486517178v2.png

    3. Create method

    SendMail(MailTitle : Text;MailBody : Text;EmployeeEmail : Text)
    SMTPSetup.GET;
    SenderMail := SMTPSetup."User ID"; //Default mail account
    
    // Compose the message -------------------------------
    MailBody  = '

    '; MailBody := MailBody 'Best Regards' '
    '; MailBody := MailBody FORMAT(USERID) '
    '; MailBody := MailBody FORMAT(COMPANYNAME) '
    '; MailBody := MailBody '______' '


    '; MailBody := MailBody 'This message was created automatically.' '
    '; //send the message SMAIL.CreateMessage('nameofsender', SenderMail, EmployeeEmail, MailTitle, MailBody, TRUE); SMAIL.AddCC('mail@mail.com'); SMAIL.Send;

    and after the method is coded you can simply add the method to some action that post your invoices and do some logic arround.

  • Community Member Profile Picture
    on at

    In  which codeunit i want to write this codes is this code unit under 400 or something else

  • Community Member Profile Picture
    on at

    Hey,

    the author of the post probably created some action on page to post the invoice. Therefore you can create the method in the page and on that action simply call method [SendMail] to run the code. There is no codeunit necessary :)

  • Community Member Profile Picture
    on at

    I getting the email but the report for the particular purchase invoice is not showing how to attach the invoice report  

  • Community Member Profile Picture
    on at

    Hey,

    I see two options,

    the first requires the recipient has NAV client. If yes you can create a link in mail using html and links docs.microsoft.com/.../creating-and-running-hyperlinks

    after that the recipient is able to open report directly from mail.

    the second relies on creating a file from report like PDF and then you can use method SMAIL.addAttachment and send the report as a file.

  • Community Member Profile Picture
    on at

    Thanks for you are update , i  follow the instruction which was given by you and now i am getting a dot net error, and i just mentioned below

    A DotNet variable has not been instantiated. Attempting to call Microsoft.Dynamics.Nav.SMTP.SmtpMessage.AddAttachment in CodeUnit Purch.-Post: SMTPMail

  • Community Member Profile Picture
    on at

    Could you please show the code ?

  • Community Member Profile Picture
    on at

    Sure

    SMTPSetup.GET;

    SenderMail := SMTPSetup."User ID";

    MailBody += '<br><br>';

    MailBody := MailBody + 'Best Regards' + '<br>';

    MailBody := MailBody + FORMAT(USERID) + '<br>';

    MailBody := MailBody + FORMAT(COMPANYNAME) + '<br>';

    MailBody := MailBody + '_____' + '<br><br><br>';

    MailBody := MailBody + 'This message was created automatically.' + '<br>';

    rec_purchinv.RESET;

    rec_purchinv.SETRANGE("No.",PurchInvHeader."No.");

    IF rec_purchinv.FINDLAST THEN

     REPORT.SAVEASPDF(406,'E:\Purchase Invoices\Purchaseinvoice.pdf',rec_purchinv);

    SMAIL.CreateMessage('guru','xxr@gmail.com','MM@gmail.com','Report',MailBody,TRUE,'Purchase Invoice','Dear Yog  Please find the attached Purchase Invoice Document FOR your ref','test');

    SMAIL.AddCC('XX.com');

    SMAIL.Send;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans