Send email alerts in axapta using x++ code

Send email alerts in axapta using x++ code


 str relayServer;  
 InteropPermission interopPermission;  
 SysMailer mailer;  
 SysEmailParameters parameters = SysEmailParameters::find();  
 ;  
 if (parameters.SMTPRelayServerName)  
 relayServer = parameters.SMTPRelayServerName;  
 else  
 relayServer = parameters.SMTPServerIPAddress;  
 interopPermission = new InteropPermission(InteropKind::ComInterop);  
 interopPermission.assert();  
 mailer = new SysMailer();  
 CodeAccessPermission::revertAssert();  
 mailer.SMTPRelayServer( relayServer,  
 parameters.SMTPPortNumber,  
 parameters.SMTPUserName,  
 SysEmailParameters::password(),  
 parameters.NTLM  
 );  
 mailer.fromAddress("test@test.com");  
 mailer.tos().appendAddress("sdf@dsf.com");  
 mailer.subject("Test with email setting");  
 mailer.htmlBody("Testing cc");  
 mailer.sendMail();