• About

Day 2 Day Dynamics

~ Experiences of a working AX developer

Day 2 Day Dynamics

Tag Archives: AX Email

Send-Email custom PowerShell function

13 Friday Mar 2015

Posted by John Hagler in Powershell

≈ 5 Comments

Tags

Automation, AX, AX 2012, AX Email, Build Scripts, Dynamics AX, PowerShell, Setup

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.

Follow Day 2 Day Dynamics on WordPress.com

Day 2 Day Dynamics

  • RSS - Posts
  • RSS - Comments

Follow me on Twitter

My Tweets

Recent Posts

  • Minimizing Database Calls
  • Push-AXModel custom PowerShell function
  • Clean-AXModel custom PowerShell function
  • Get-AXTFSCombinedXpo custom PowerShell Function
  • Refresh-AXAifPort custom PowerShell function

Archives

  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015

John Hagler

John Hagler

John Hagler

I am the Dynamics AX Technical Architect at Dealer.com. I have been working with AX since Sep. 2006, starting with Axapta 3.0. I have worked as both a VAR and an AX customer.

View Full Profile →

Blog at WordPress.com.

  • Follow Following
    • Day 2 Day Dynamics
    • Already have a WordPress.com account? Log in now.
    • Day 2 Day Dynamics
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar