Пример #1
0
        public void NewPostEmail(IEnumerable <Subscription> Subs, Post ThePost, Thread thread, string PostURL)
        {
            ListDictionary replacements  = new ListDictionary();
            string         AutoFromEmail = SiteConfig.AutomatedFromEmail.Value;

            MailDefinition md = new MailDefinition();

            md.BodyFileName = EmailTemplates.GenerateEmailPath(EmailTemplates.NewThreadReply);
            md.IsBodyHtml   = true;
            md.From         = AutoFromEmail;
            md.Subject      = "Reply to Thread '" + thread.Title + "' - " + SiteConfig.BoardName.Value;

            replacements.Add("{REPLY_USERNAME}", ThePost.User.Username);
            replacements.Add("{REPLY_TEXT}", ThePost.Text);
            replacements.Add("{THREAD_TITLE}", thread.Title);
            replacements.Add("{POST_URL}", PostURL);
            replacements.Add("{BOARD_URL}", SiteConfig.BoardURL.Value);
            replacements.Add("{BOARD_NAME}", SiteConfig.BoardName.Value);

            System.Web.UI.Control ctrl = new System.Web.UI.Control {
                ID = "Something"
            };

            MailMessage message = md.CreateMailMessage("*****@*****.**", replacements, ctrl);

            //Send the message
            SmtpClient client = Settings.GetSmtpClient();

            foreach (Subscription s in Subs)
            {
                if (s.UserID == ThePost.UserID)
                {
                    continue;
                }
                User u = s.User;
                message.To.Clear();
                message.To.Add(u.Email);
                try
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(state => client.Send(message));
                }
                catch
                {
                }
            }
        }
Пример #2
0
        private void SendEmail(
            string toEmail,
            string fromEmail,
            string subject,
            string template,
            ListDictionary replacements,
            bool isHtml = true)
        {
            string boardUrl = SiteConfig.BoardURL.Value;

            if (boardUrl.EndsWith("/"))
            {
                boardUrl = boardUrl.TrimEnd('/');
            }

            replacements.Add("{BOARD_URL}", boardUrl);
            replacements.Add("{BOARD_NAME}", SiteConfig.BoardName.Value);

            MailDefinition md = new MailDefinition();

            string templatePath = EmailTemplates.GenerateEmailPath(template);

            md.BodyFileName = templatePath;
            md.IsBodyHtml   = isHtml;
            md.From         = fromEmail;
            md.Subject      = subject;

            MailMessage message = md.CreateMailMessage(toEmail, replacements, new System.Web.UI.Control());

            SmtpClient client = Settings.GetSmtpClient();

            try
            {
                client.SendAsync(message, null);
            }
            catch
            {
            }
        }