Ejemplo n.º 1
0
        public Template(string filename, bool IsHTML)
        {
            //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;

            this.IsHTML = IsHTML;

            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) { }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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) { }
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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) { }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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 }));
        }
Ejemplo n.º 9
0
        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 }));
        }