Tags

, , , , , , ,

When looking at automating my AX 2012 processes, the first thing I was interested in was the ability to send emails when steps were completed.  This would allow me to kick off my process and walk away, tracking it on my phone if necessary.

The function I created for this is Send-Email and can be found on Codeplex.  It takes 7 parameters:

  • SMTPServer (SMTP server that will send the email)
  • From (Who the email is from)
  • To (Who the email is to)
  • Subject (Email subject)
  • Body (Email body)
  • Priority (Email priority)
  • FileLocation (Allows you to attach a file if used.  I primarily use this to attach my log files)

This function uses the Net.Mail.MailMessage and Net.Mail.SmtpClient to send an email message.  I usually default some of these parameters in the scripts I use to call these functions but we’ll get into that when I walk through my build function.  You can view the code in this function using PowerShell ISE.

The way that I currently test and run these standalone PowerShell functions is to use my profile.  In my profile, I include a link to a PowerShell script that holds my function locations.  I do this so that when I add new functions, I can just include them in my D2D_PSFunctions.ps1 script and they will be automatically included by my profile the next time I open up PowerShell.  You can get more info on what I’m doing in an earlier post as well as Codeplex.

Please take a look at this function to get an idea of what is going on.  There may be optimizations or better ways to do things in PowerShell but I was teaching myself PowerShell while I wrote all of this.