using System; using System.Collections.Specialized; using System.Configuration.Provider; using System.IO; namespace SPSolutions.Net.Mail { public class FileMailBodyProvider : MailBodyProvider { private string _templateSourceDirectory; public string TemplateSourceDirectory { get { return this._templateSourceDirectory; } set { this._templateSourceDirectory = value; } } public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "FileMailBodyProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "ProfileSqlProvider_description"); } base.Initialize(name, config); this._templateSourceDirectory = config["templateSourceDirectory"]; if (string.IsNullOrEmpty(this._templateSourceDirectory)) { throw new ProviderException("Connection_name_not_specified"); } config.Remove("templateSourceDirectory"); if (config.Count > 0) { string key = config.GetKey(0); if (!string.IsNullOrEmpty(key)) { throw new ProviderException("Provider_unrecognized_attribute"); } } } public override string RetrieveMailBody(string bodyContainerName) { string result = string.Empty; FileInfo fileInfo = new FileInfo(this.TemplateSourceDirectory + bodyContainerName); if (!fileInfo.Exists) { throw new Exception("no file"); } using (TextReader textReader = new StreamReader(fileInfo.FullName)) { result = textReader.ReadToEnd(); } return result; } } }