/// <summary> /// Lists this instance. /// </summary> /// <returns></returns> public static SmtpBox[] List() { List <SmtpBox> retVal = new List <SmtpBox>(); foreach (SmtpBoxRow row in SmtpBoxRow.List()) { retVal.Add(new SmtpBox(row)); } return(retVal.ToArray()); }
/// <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); } }
/// <summary> /// Gets the default. /// </summary> /// <returns></returns> public static SmtpBox GetDefault() { SmtpBoxRow[] rows = SmtpBoxRow.List(FilterElement.EqualElement(SmtpBoxRow.ColumnIsDefault, true)); // Fix No Default Problem if (rows.Length == 0) { rows = SmtpBoxRow.List(); } if (rows.Length > 0) { return(new SmtpBox(rows[0])); } return(null); }
/// <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(); } }
/// <summary> /// Commits the test email. /// </summary> /// <param name="checkUid">The check uid.</param> /// <returns></returns> public static bool CommitTestEmail(Guid checkUid) { SmtpBoxRow[] rows = SmtpBoxRow.List(FilterElement.EqualElement(SmtpBoxRow.ColumnCheckUid, checkUid)); if (rows.Length > 0) { using (TransactionScope tran = DataContext.Current.BeginTransaction()) { foreach (SmtpBoxRow row in rows) { row.Checked = true; row.Update(); } tran.Commit(); } } return(rows.Length > 0); }
/// <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(); } }
/// <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; }
/// <summary> /// Totals the count. /// </summary> /// <returns></returns> public static int TotalCount() { return(SmtpBoxRow.GetTotalCount()); }