Ejemplo n.º 1
0
        public static string Process(string templateFile, Dictionary<string, object> properties)
        {
            var templateProcessor = new SimpleTemplateProcessor();
            var processedContent = templateProcessor.Execute(properties, templateFile);

            if (templateProcessor.Errors.Count > 0)
            {
                throw new Exception(string.Format(CultureInfo.CurrentCulture, "Template processing has failed: {0}", templateProcessor.ErrorsString));
            }

            return processedContent;
        }
Ejemplo n.º 2
0
        public static string Process(string templateFile, Dictionary <string, object> properties)
        {
            var templateProcessor = new SimpleTemplateProcessor();
            var processedContent  = templateProcessor.Execute(properties, templateFile);

            if (templateProcessor.Errors.Count > 0)
            {
                throw new Exception(string.Format(CultureInfo.CurrentCulture, "Template processing has failed: {0}", templateProcessor.ErrorsString));
            }

            return(processedContent);
        }
Ejemplo n.º 3
0
        private void SendEmail(string templateName, EmailContext context)
        {
            if (context != null)
            {
                // short Circuit, If there is DropEmail set, we dont have to send this email.
                if (context.DropEmail)
                {
                    return;
                }

                var emailService  = CreateEmailService();
                var emailTemplate = GetEmailTemplate(templateName);
                var emailBody     = SimpleTemplateProcessor.Process(emailTemplate, context.PlaceHolders);

                var fromAddress = GetFromAddress();

                var mailMessage = new MailMessage
                {
                    From = fromAddress
                };

                // Add To address
                foreach (var toAddress in context.ToAddress)
                {
                    mailMessage.To.Add(toAddress);
                }

                // Add cc address
                foreach (var ccAddress in context.CcAddress)
                {
                    mailMessage.CC.Add(ccAddress);
                }

                // Set Subject
                mailMessage.Subject = context.Subject;

                // Set Body
                mailMessage.Body       = emailBody;
                mailMessage.IsBodyHtml = true;

                if (context.EmailAttachments.Any())
                {
                    foreach (var emailAttachment in context.EmailAttachments)
                    {
                        Stream stream = new MemoryStream(emailAttachment.Content);
                        mailMessage.Attachments.Add(new Attachment(stream, emailAttachment.FileName, emailAttachment.FileType));
                    }
                }

                emailService.SendEmail(mailMessage);
            }
        }