Beispiel #1
0
        /// <summary>
        /// Sends the test email.
        /// </summary>
        /// <param name="smtpBoxId">The SMTP box id.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="htmlBody">The HTML body.</param>
        /// <param name="completeCheckPageUrl">The complete check page URL.</param>
        public static void SendTestEmail(int smtpBoxId, string subject, string htmlBody, string completeCheckPageUrl)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }
            if (htmlBody == null)
            {
                throw new ArgumentNullException("htmlBody");
            }
            if (completeCheckPageUrl == null)
            {
                throw new ArgumentNullException("completeCheckPageUrl");
            }

            SmtpBoxRow row = new SmtpBoxRow(smtpBoxId);

            // Reset Check params
            row.Checked  = false;
            row.CheckUid = Guid.NewGuid();

            row.Update();

            // Create Complete Back Link
            string backLink = completeCheckPageUrl + "?uid=" + row.CheckUid.ToString();

            SmtpClient client = SmtpClientUtility.CreateSmtpClient(new SmtpBox(row));

            string to = Security.CurrentUser.Email;

            // Create Mail Message
            MailMessage tesMsg = new MailMessage();

            MailAddress currentUser = new MailAddress(to, Security.CurrentUser.DisplayName);

            tesMsg.To.Add(currentUser);
            tesMsg.From    = currentUser;
            tesMsg.Subject = subject;

            tesMsg.IsBodyHtml = true;
            tesMsg.Body       = htmlBody + "<br/><a href='" + backLink + "'>" + backLink + "</a>";

            client.Send(tesMsg);

            if (!string.IsNullOrEmpty(tesMsg.ErrorMessage))
            {
                throw new SmtpException(tesMsg.ErrorMessage);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets the default.
        /// </summary>
        /// <param name="smtpBoxId">The SMTP box id.</param>
        public static void SetDefault(int smtpBoxId)
        {
            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                // Reset All Default
                foreach (SmtpBoxRow row in SmtpBoxRow.List(FilterElement.EqualElement(SmtpBoxRow.ColumnIsDefault, true)))
                {
                    row.IsDefault = false;
                    row.Update();
                }

                SmtpBoxRow newDefaultRow = new SmtpBoxRow(smtpBoxId);
                newDefaultRow.IsDefault = true;
                newDefaultRow.Update();

                tran.Commit();
            }
        }