User Guide

Send Email

You can send email in Project Automation either manually with your own code or via the SendEmail helper method.

SendEmail Method

The Project Automation base class, provides a wrapper around the .NET SmtpClient class. This allows you to simply call this method to send email.

For example

public override void End(ProjectAutomationResult result)
{
    if ( result.Success && result.HasChanges ) 
    {                        
        //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
        SendEmail("to@domain.com", "Synchronisation Result", message);    
    }
}

You can specify the SMTP Server settings in-line or via Project Properties additionally if you have re-directed the ValuesService to Ouvvi these settings can come from Ouvvi system settings.

  • SMTPServer - Server Address of your SMTP Server
  • SMTPPort - TCP Port of your SMTP Server (typically 25 or 587)
  • SMTPUsername - Username for your SMTP Server
  • SMTPPassword - Password for your SMTP Server
  • SMTPUseSSL - True/False if your SMTP Server uses SSL/TLS
  • SupportEmail - Email address to use as the From address if not supplied.

.NET SmtpClient

To send email via the .NET SmtpClient class, simply implement your code in the End() method.

For example

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@domain.com", "to@domain.com", "Synchronisation Result", message);                                                    
    }
}