Monday 22 July 2013

Emailing through NAS in NAVISION 4.0 SP3

FYI..
NAV 4.0 SP3 did not  have email functionality through SMTP.(no where found it in NAV4).
Here we have sample code which is tested and worked fine for me.

Variable:
Name DataType Subtype Length
objEmailConf Automation 'Microsoft CDO for Windows 2000 Library'.Configuration
objEmail Automation 'Microsoft CDO for Windows 2000 Library'.Message
flds Automation 'Microsoft ActiveX Data Objects 2.5 Library'.Fields
fld Automation 'Microsoft ActiveX Data Objects 2.5 Library'.Field

Sample Code:

 IF ISCLEAR(objEmailConf) THEN CREATE(objEmailConf); 
 flds := objEmailConf.Fields;
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/smtpserver'); 
fld.Value('Smtp Server'); //here EX:smtp.gmail.com 
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/smtpauthenticate') ;
fld.Value('1'); //we have 3 oprions.1 means basic one means it require authentiaction
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/sendusing');
fld.Value('2');
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/sendusername') ; fld.Value('xyz@urdomain.com');//sender user name 
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/sendpassword') ;
fld.Value('password'); //sender password
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/smtpserverport'); 
fld.Value('25'); //Dafault Port Number is 25
fld := flds.Item('http://schemas.microsoft.com/cdo/configuration/smtpusessl');
fld.Value('TRUE');      //Enable SSL if your smtp server allow only Https protocaol
flds.Update;
IF ISCLEAR(objEmail) THEN CREATE(objEmail); 
objEmail.Configuration := objEmailConf;
objEmail.From := 'Sender Name'; 
objEmail."To" := 'Reciepent Email Id';
objEmail.Subject := 'Text Subject';
objEmail.TextBody := 'Test Body';
objEmail.Send; 

No comments:

Post a Comment