Announcements
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
Do you have SMTP Mail Setup table, User Setup table and SMTP Mail codeunit ?
Thanks for the response
I have those things
I use to send mails using that steps
1. Create variables
2.Create parameters
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.
In which codeunit i want to write this codes is this code unit under 400 or something else
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 :)
I getting the email but the report for the particular purchase invoice is not showing how to attach the invoice report
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.
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
Could you please show the code ?
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.