Ejemplo n.º 1
0
        public MailMessage Parse(IMailTemplate template, object model)
        {
            var context = new VelocityContext();
            var args    = GetArgs(model);

            if (!args.ContainsKey("helper"))
            {
                context.Put("helper", new TemplateHelper());
            }

            foreach (var arg in args)
            {
                context.Put(arg.Key, arg.Value);
            }


            var result = "";

            using (var sw = new StringWriter()) {
                var content = template.ToStringContent();
                NVelocityDirectResourceLoader.CurrentEncoding = template.Encoding;
                var tmp = engine.GetTemplate(content, template.Encoding.EncodingName);
                tmp.Merge(context, sw);

                result = sw.ToString();
            }
            return(XmlMailSerializer.Deserialize(result));
        }
Ejemplo n.º 2
0
        public MailMessage Parse(IMailTemplate template, object model)
        {
            var viewBag = new DynamicViewBag();

            viewBag.AddValue("Helper", new TemplateHelper());

            var content = template.ToStringContent();
            var result  = Razor.Parse(content, model, viewBag, template.Location);

            return(XmlMailSerializer.Deserialize(result));
        }