Modifying email templates for Navision 5.0

457 views Asked by At

I've been asked to help do some much needed updates to Microsoft Dynamics NAV 5.0 (yes its old) and they want me to update some of their email templates for sales orders, etc. One of the things they want me to do is update the 'From' field to be a group email box instead of the current user, which I didn't think about be too difficult, but figuring out how NAV creates emails has been less than simple.

This article had some information, but didn't get me all the way there: http://www.dynamics101.com/2014/02/sending-customized-emails-dynamics-nav/

I've found the Sales Header table which has lots of fields...none of which include "From". I found one field called "Assigned User" which points to the User Setup.

1

There are 1 answers

1
Alexander Drogin On BEST ANSWER

Do you mean the mails that are sent on the event of sales order approval / rejection or that small 'New Mail Message' button in the Customer card? Libraries that are used in these cases are different, and they rely on different automation objects to create e-mail messages. Anyway, in both cases there is no setup to change the 'From' field - you'll have to customize it a bit.

First of all, you'll need a new field in a setup table to store the e-mail address. Table 'User Setup' is probably the best place, but it depends on the task, of course. Suppose, it is Uset Setup, and you call the new field 'FromAddress'

When you click on the e-mail button in the Customer card, 'Create Mail' wizard is run (Form 5148 'Create Mail'). It calls the function 'NewMessage' in codeunit 397. So, codeunit 397 'Mail', is what you are looking for. To change the 'From' address you need to set the property 'SentOnBehalfOfName' in the OSendMail object.

UserSetup.GET(USERID);
OSendMail.SentOnBehalfOfName(UserSetup.FromAddress);

If the message you want to change is the document approval notification, e-mail message is created in the codeunit 400 'SMTP Mail', but all fields are set up in the codeunit 440 'Approvals Mgt Notification', functions SetTemplate and GetEmailAddress. It is GetEmailAddress that sets the sender address. You need to replace this line of code:

SenderAddress := UserSetup."E-Mail";

with the new one

SenderAddress := UserSetup.FromAddress;

But be careful - this change will affect all templates and all users. If you need to change some templates while leaving other untouched, it is safer to redefine the value of this variable in a function responsible for the particular template. But again, it's all in codeunit 440.