Friday, June 26, 2009

Email from Ax by CLR interop

In my previous post, I talked about the CLR Interop possibilities from Dynamics Ax. As you might know, CLR interop is used to get access to assemblies installed with the .NET Framework, or even the assemblies you create on your own with Visual Studio.

Here's another example. This time, we are going to send an email from Ax with it. (Yes I know, this kind of functionalities are provided with Ax out-of-the-box as well.)

void Email()
{ System.Net.Mail.MailMessage myMailMessage;
System.Net.Mail.SmtpClient myMail;
System.Net.Mail.MailAddress myMailFrom;
System.Net.Mail.MailAddress myMailTo;
System.Net.NetworkCredential myNC;

str mySubject="Mail from Ax 2009";
str myMailBody="The email body goes here";
str myMailFromStr="";
str myMailToStr="";
str mysmtpServer="yourmailservername";
str mylogin="loginname";
str mypassword="loginpassword";

myMailFrom = new System.Net.Mail.MailAddress(myMailFromStr,myMailFromStr);
myMailTo = new System.Net.Mail.MailAddress(myMailToStr,myMailToStr);
myMailMessage = new System.Net.Mail.MailMessage(myMailFrom,myMailTo);
myMail = new System.Net.Mail.SmtpClient(mysmtpServer);
myNC= new System.Net.NetworkCredential(mylogin,mypassword);

Supplying of the network credentials is optional. If not specified, the default network credentials will be used. Depending on your email server settings (relay on/off), only emails to the local domain are allowed.

This example can be extended, to include file attachments for example.



1 comment:

  1. Such as very good information promoting content are provided and more skills are improved after refer that post.For more details about oracle fusion financial please check our website. Oracle Fusion Financial Training Institute