public Template(string filename, bool is_html, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], mainconfigname); FromName = readConfig.SenderName; FromEmail = readConfig.SenderEmail; IsHTML = is_html; try { System.IO.TextReader fileReader = new System.IO.StreamReader(filename); StringBuilder templateBuilder = new StringBuilder(""); Subject = fileReader.ReadLine(); Subject.Remove(0, 8); string line; // Read lines from the file until the end of // the file is reached. while ((line = fileReader.ReadLine()) != null) { templateBuilder.AppendLine(line); } this.Body = templateBuilder.ToString(); } catch (System.Exception) { } }
public Template() { //MailerConfiguration readConfig = (MailerConfiguration)System.Configuration.ConfigurationManager.GetSection("mail"); MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], "mail"); FromName = readConfig.SenderName; FromEmail = readConfig.SenderEmail; }
public Template(StringBuilder email, string subject, bool IsHTML, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], mainconfigname); FromName = readConfig.SenderName; FromEmail = readConfig.SenderEmail; Subject = subject; Body = email.ToString(); this.IsHTML = IsHTML; }
public Template(StringBuilder email, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], mainconfigname); FromName = readConfig.SenderName; FromEmail = readConfig.SenderEmail; try { int len = email.ToString().IndexOf("."); Subject = email.ToString().Substring(0, len); email.Remove(0, len + 1); Body = email.ToString(); } catch (System.Exception) { } }
static Mailer() { //MailerConfiguration readConfig = (MailerConfiguration)System.Configuration.ConfigurationManager.GetSection("mail"); MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], "mail"); MailerConfiguration boundConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], "returnpath"); if (readConfig != null) { _smtpConfig = readConfig; } if (boundConfig != null) { replyTo = new MailAddress(boundConfig.SenderEmail, boundConfig.SenderName); } else { replyTo = null; } }
public Template(string filename, string directory, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(directory, mainconfigname); FromName = readConfig.SenderName; FromEmail = readConfig.SenderEmail; try { System.IO.TextReader fileReader = new System.IO.StreamReader(filename); StringBuilder templateBuilder = new StringBuilder(""); Subject = fileReader.ReadLine(); string line; while ((line = fileReader.ReadLine()) != null) { templateBuilder.AppendLine(line); } this.Body = templateBuilder.ToString(); } catch (System.Exception) { } }
public static MailMessage RenderPlainHTMLEmail(string mainconfigname, string subject, string htmlText, string plainText, string email, string nameto, Dictionary <string, string> emailHeaders) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], mainconfigname); MailMessage message = new MailMessage(new MailAddress(readConfig.SenderEmail, readConfig.SenderName), String.IsNullOrEmpty(nameto) ? new MailAddress(email) : new MailAddress(email, nameto)); try { message.Subject = subject; message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(plainText, Encoding.UTF8, MediaTypeNames.Text.Plain)); message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(htmlText, Encoding.UTF8, MediaTypeNames.Text.Html)); message.Headers.Add("List-Unsubscribe", "<mailto:" + readConfig.SenderEmail + "?subject=" + email + ">"); if (emailHeaders != null && emailHeaders.Count > 0) { foreach (var nvc in emailHeaders) { message.Headers.Add(nvc.Key, nvc.Value); } } } catch (Exception) { } return(message); }
public static void Enqueue(MailMessage message, string directory, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(directory, mainconfigname); System.Threading.ThreadPool.QueueUserWorkItem(MailSenderThreadArray, (object)(new object[] { message, readConfig })); }
public static void Enqueue(MailMessage message, string mainconfigname) { MailerConfiguration readConfig = ConfigurationHandler.GetSection(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["MailConfig"], mainconfigname); System.Threading.ThreadPool.QueueUserWorkItem(MailSenderThreadArray, (object)(new object[] { message, readConfig })); }