Exemplo n.º 1
0
        /// <summary>
        /// Generates the E-mail body content using a XSL Transformation and a EmailTemplateParameters object
        /// to set the input data required by the XSL Template.
        /// </summary>
        /// <param name="templatePath">XSL Tranformation template</param>
        /// <param name="templateProperties">Properties required by the XSL Transformation template</param>
        /// <returns>Generated body content</returns>
        public static string GenerateEmailBody(string templatePath, EmailTemplateParameters templateProperties)
        {
            // Convert properties to XML
            XElement element = new XElement(
                "Properties",
                from keyValue in templateProperties
                select new XElement(keyValue.Key, keyValue.Value));

            XDocument document = new XDocument();

            document.Add(element);

            return(GenerateEmailBody(templatePath, document));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates and sends an E-mail using a XSL Transformation template to generate the body content.
        /// </summary>
        /// <param name="recipient">E-mail address of 'To' field</param>
        /// <param name="subject">E-mail subject</param>
        /// <param name="templatePath">XSL Tranformation template</param>
        /// <param name="templateProperties">Properties required by the XSL Transformation template</param>
        public static void Send(string recipient, string subject, string templatePath, EmailTemplateParameters templateProperties)
        {
            MailMessage mailMessage = CreateMailMessage(recipient, subject, templatePath, templateProperties);

            Send(mailMessage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a MailMessage object with a dynamically generated body and the specified parameters.
        /// </summary>
        /// <param name="recipient">E-mail address of 'To' field</param>
        /// <param name="subject">E-mail subject</param>
        /// <param name="templatePath">XSL Tranformation template</param>
        /// <param name="templateProperties">Properties required by the XSL Transformation template</param>
        /// <returns>MailMessage instance to be sent</returns>
        public static MailMessage CreateMailMessage(string recipient, string subject, string templatePath, EmailTemplateParameters templateProperties)
        {
            string body = EmailTemplate.GenerateEmailBody(templatePath, templateProperties);

            MailMessage mailMessage = CreateMailMessage(body);

            mailMessage.Subject = subject;
            mailMessage.To.Add(new MailAddress(recipient));

            return(mailMessage);
        }