View All Blog Posts

Using Automation to Send Email

With the new Automation feature of Data Synchronisation Studio it is now incredibly easy to write custom actions in the pipeline. For example suppose you wanted an email sent whenever a synchronisation has run and you want to know the changed counts.

You simply implement the End method of the Automation Class and send an SMTP Email message like this.

public override void End(ProjectAutomationResult result)
    {
        if ( result.Success && result.HasChanges ) 
        {            
            var smtpClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new System.Net.NetworkCredential("username", "password");
            
            //Message to Send
            string message = string.Format("New {0}, Updated {1}, Deleted {2}", 
                result.CompareResult.New.Count, 
                result.CompareResult.Updated.Count, 
                result.CompareResult.Deleted.Count);
        
            //Send Message
            smtpClient.Send("from@simego.com", "to@simego.com", "Synchronisation Result", message);                                                    
        }
    }
| Wednesday, June 13, 2012 |