예제 #1
0
파일: SmtpBox.cs 프로젝트: 0anion0/IBN
        /// <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();
            }
        }
예제 #2
0
파일: SmtpBox.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Deletes the specified SMTP box id.
        /// </summary>
        /// <param name="smtpBoxId">The SMTP box id.</param>
        public static void Delete(int smtpBoxId)
        {
            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                // TODO: Check that exists element with IsDefault = 1
                SmtpBoxRow row = new SmtpBoxRow(smtpBoxId);
                row.Delete();

                if (row.IsDefault)
                {
                    // Set First SMTP Box As Default
                    SmtpBox newDefaultBox = GetDefault();
                    if(newDefaultBox!=null)
                    {
                        newDefaultBox.SourceRow.IsDefault = true;
                        newDefaultBox.SourceRow.Update();
                    }
                }

                tran.Commit();
            }
        }
예제 #3
0
파일: SmtpBox.cs 프로젝트: 0anion0/IBN
        /// <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);
            }
        }
예제 #4
0
파일: SmtpBox.cs 프로젝트: 0anion0/IBN
 /// <summary>
 /// Initializes a new instance of the <see cref="SmtpBox"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 private SmtpBox(SmtpBoxRow source)
 {
     this.SourceRow = source;
 }