public static void Send( Guid emailTemplateGuid, List<RecipientData> recipients, string appRoot = "", string themeRoot = "", bool createCommunicationHistory = true )
{
try
{
if ( recipients != null && recipients.Any() )
{
var mediumEntity = EntityTypeCache.Read( Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_EMAIL.AsGuid() );
if ( mediumEntity != null )
{
var medium = MediumContainer.GetComponent( mediumEntity.Name );
if ( medium != null && medium.IsActive )
{
var transport = medium.Transport;
if ( transport != null && transport.IsActive )
{
using ( var rockContext = new RockContext() )
{
var template = new SystemEmailService( rockContext ).Get( emailTemplateGuid );
if ( template != null )
{
try
{
if ( transport is Rock.Communication.Transport.SMTPComponent )
{
( (Rock.Communication.Transport.SMTPComponent)transport ).Send( template, recipients, appRoot, themeRoot, createCommunicationHistory );
}
else
{
transport.Send( template, recipients, appRoot, themeRoot );
}
}
catch ( Exception ex1 )
{
throw new Exception( string.Format( "Error sending System Email ({0}).", template.Title ), ex1 );
}
}
else
{
throw new Exception( string.Format( "Error sending System Email: An invalid System Email Identifier was provided ({0}).", emailTemplateGuid.ToString() ) );
}
}
}
else
{
throw new Exception( string.Format( "Error sending System Email: The '{0}' medium does not have a valid transport, or the transport is not active.", mediumEntity.FriendlyName ) );
}
}
else
{
throw new Exception( string.Format( "Error sending System Email: The '{0}' medium does not exist, or is not active (type: {1}).", mediumEntity.FriendlyName, mediumEntity.Name ) );
}
}
else
{
throw new Exception( "Error sending System Email: Could not read Email Medium Entity Type" );
}
}
}
catch ( Exception ex )
{
ExceptionLogService.LogException( ex, HttpContext.Current );
}
}