How to use the System.Net.Mail namespace to send an e-mail message in Microsoft Dynamics AX 4.0

Article ID: 952736 - View products that this article applies to.
Expand all | Collapse all

INTRODUCTION

This article describes how to use the System.Net.Mail namespace to send an e-mail message in Microsoft Dynamics AX 4.0.

More information

To use the System.Net.Mail namespace to send an e-mail message in Microsoft Dynamics AX 4.0, follow these steps:
  1. Add the System.Net reference to the Application Object Tree (AOT). To do this, follow these steps:
    1. Click Application Object Tree.
    2. Right-click References, and then click Add reference to open the Add reference dialog box.

      Note In the Add reference dialog box, all Microsoft .NET assemblies that are registered on the computer appear.
    3. Click System.Net, and then click Select.
    4. Click OK.
    5. Expand References, and then make sure that the System.Net reference appears under the References node.
  2. Create a job to use the System.Net.Mail namespace. To do this, follow these steps:
    1. Click Application Object Tree.
    2. Right-click Jobs, and then click New Job.
    3. In the \Jobs – Editor dialog box, modify the code to resemble the following X++ code:
      static void FrameworkMailSend(Args _args)
      {
           System.Net.Mail.MailMessage             mailMessage;
           System.Net.Mail.Attachment              attachment;
           System.Net.Mail.AttachmentCollection    attachementCollection;
           System.Net.Mail.SmtpClient              myMail;
           ;
       
           mailMessage = new System.Net.Mail.MailMessage("<E-mail_Address1>"," <E-mail_Address2>");
           
           // The following lines display how to create attachments.
           attachementCollection = mailMessage.get_Attachments();
           attachment = new System.Net.Mail.Attachment("<Path>\\<File>");
           attachementCollection.Add(attachment);
           
           // The following lines display how to add a subject and a body.
           mailmessage.set_Subject("<Subject>");
           mailmessage.set_Body("<Body>");
           
           // The following lines display how to send an e-mail message by using SMTP. 
           myMail = new System.Net.Mail.SmtpClient('<IP_Address>');         mymail.Send(mailmessage);
      
      }
      Notes
      • The <E-mail_Address1> placeholder and the <E-mail_Address2> placeholder represent the from e-mail address and the to e-mail address, respectively.
      • The <Path> placeholder represents the actual path from which you obtain the file that you want to attach. The <File> placeholder represents the actual file that you want to attach.
      • The <Subject> placeholder represents the actual subject of the e-mail message. The <Body> placeholder represents the actual body content of the e-mail message.
      • The <IP_Address> placeholder represents the actual IP address of the SMTP server.
  3. Run the job.
After you run the job, the e-mail message is sent if the following conditions are true:
  • The IP address of the SMTP server that you set is correct.
  • The port that you use is not blocked. By default, the port is port 25.

References

For more information about the System.Net.Mail namespace, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/system.net.mail.aspx

Properties

Article ID: 952736 - Last Review: July 14, 2012 - Revision: 4.0
Applies to
  • Microsoft Dynamics AX 4.0
  • Windows MorphX Development Suite
Keywords: 
kbexpertiseadvanced kbmbsmigrate kbhowto KB952736

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com