Sending an e-mail from NAV through Outlook
Dynamics NAV has code that will integrate with your Outlook client to send an e-mail. This recipe will show you how to leverage that code.
Getting ready
You must have Outlook, or some other e-mail client, installed on the machine.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
Subtype
SMTPMailSetup
Record
SMTP Mail Setup
SMTPMail
Record
SMTP Mail
Mail
Record
Mail
Selection
Integer
Add the following code to the
OnRun
trigger of your codeunit:Selection := STRMENU('SMTP,Standard); IF Selection = 1 THEN BEGIN IF SMTPMailSetup.GET THEN BEGIN SMTPMail.CreateMessage('Matt Traxinger', 'YourE-mail@microsoft.com', 'Someone@somewhere.com', 'E-mail Subject', 'E-mail Body', FALSE); SMTPMail.Send; END; END ELSE BEGIN Mail.NewMessage('Navision.Programmer@gmail.com', '','E-mail Subject','E-mail Body','',TRUE); END;
Save and close the codeunit.
How it works...
When you run the codeunit you will be...