public static void BuildEmailBodyByTemplate(MailMessage mailInfoMessage, string templateID, KeyValueVariables keyValues, KeyTableVariables keyTables, string languageCode) { if (!string.IsNullOrEmpty(templateID)) { MailTemplate getTemplate = GetTemplateByID(templateID, languageCode); mailInfoMessage.FromName = getTemplate.Sender; mailInfoMessage.DisplaySenderName = getTemplate.SenderDisplayName; mailInfoMessage.ToName = (!string.IsNullOrEmpty(getTemplate.To) ? getTemplate.To + ";" : string.Empty) + mailInfoMessage.ToName; mailInfoMessage.IsHtmlType = getTemplate.IsHtmlType; mailInfoMessage.Priority = getTemplate.MailPriority; //构建MailSubject: mailInfoMessage.Subject = BuildMailSubject(getTemplate.Subject, keyValues); //构建MailBody: mailInfoMessage.Body = TemplateString.BuildHtml(getTemplate.Body, keyValues, keyTables); } else { throw new ArgumentException("参数不能为null或空白字符串!", "templateID"); } }
private string BuildHtml(string templateFileFullPath, KeyValueVariables variables, KeyTableVariables tableVariables) { string html = File.ReadAllText(templateFileFullPath, Encoding.UTF8); return(TemplateString.BuildHtml(html, variables, tableVariables)); }