public static Send ( System.Guid emailTemplateGuid, List |
||
emailTemplateGuid | System.Guid | The email template unique identifier. |
recipients | List |
The recipients. |
appRoot | string | The application root. |
themeRoot | string | The theme root. |
createCommunicationHistory | bool | if set to |
리턴 | void |
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 );
}
}
Email::Send ( string fromEmail, string subject, List |
|
Email::Send ( string fromEmail, string fromName, string subject, List |
protected void btnSend_Click( object sender, EventArgs e ) { PersonService personService = new PersonService(); var mergeObjects = new List<object>(); var values = new Dictionary<string, string>(); values.Add( "ConfirmAccountUrl", RootPath + "ConfirmAccount" ); mergeObjects.Add( values ); Dictionary<object, List<object>> personObjects = new Dictionary<object, List<object>>(); foreach(Person person in personService.GetByEmail(tbEmail.Text)) { var userObjects = new List<object>(); UserService userService = new UserService(); foreach ( User user in userService.GetByPersonId( person.Id ) ) if ( user.AuthenticationType != AuthenticationType.Facebook ) userObjects.Add( user ); if ( userObjects.Count > 0 ) personObjects.Add( person, userObjects ); } if ( personObjects.Count > 0 ) { mergeObjects.Add( personObjects ); var recipients = new Dictionary<string, List<object>>(); recipients.Add( tbEmail.Text, mergeObjects ); Email email = new Email( Rock.SystemGuid.EmailTemplate.SECURITY_FORGOT_USERNAME ); SetSMTPParameters( email ); email.Send( recipients ); pnlEntry.Visible = false; pnlSuccess.Visible = true; } else pnlWarning.Visible = true; }