Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

how to send report to email after posting the purchase invoice

(0) ShareShare
ReportReport
Posted on by 225

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    I got the answer and thanks for your help

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice
    [quote user="ManimaranK"]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');[/quote]

    First of all,

    if you want to add some text you shall rather change MailBody. Please see what arguments CreateMessage method gets.

    Additionally I don't see where you want to add attachment to the mail.

    Have you debugged that code ?

    Regards

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    Could you please show the code ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to send report to email after posting the purchase invoice

    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.

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

News and Announcements

Announcing Category Subscriptions!

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,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans