protected void btnSend_Click(object sender, System.EventArgs e) { try { BusinessServices.Email objMail = new BusinessServices.Email(); BusinessServices.User objUser = new BusinessServices.User(); // Get the current users details. DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); // Setup email header string strFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); string strToEmail = txtToEmail.Text; string strToName = txtToEmail.Text; objMail.setUserCopyEmailBody(txtBody.Text); objMail.SendEmail(strToEmail, strToName, strFromEmail, strFromName, null, null, lblSubject.Text, lblMailServer.Text, UserContext.UserData.OrgID, 0); this.lblMessage.Text = "Email sent to " + strToName + ". Please check!"; this.lblMessage.CssClass = "SuccessMessage"; } catch (Exception ex) { this.lblMessage.Text = ex.Message; } }
private void btnSendEmail_Click(object sender, System.EventArgs e) { string strSubject = txtsubject.Text; // get the subject string strEmailBodyTemplate = txtEmailBody.Text; // get the email text string strEmailBody = ""; string strEmailAddress; string strEmailToName; string strUsers =""; BusinessServices.Email objEmail = new BusinessServices.Email(); // Get the current users details. BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); // Setup email header string strEmailFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strEmailFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); // Validate that the user has a valid recipient, subject and body. if (this.txtUserIDs.Text.Length > 0 && strSubject.Length > 0 && strEmailBodyTemplate.Length > 0) { DataTable dtbUsers = objUser.GetEmails(this.txtUserIDs.Text); DataTable dtbEmailAddresses = objUser.GetEmails(this.txtUserIDs.Text); // For each user in the table foreach(DataRow drwEmailAddress in dtbEmailAddresses.Rows) { // get the email address strEmailAddress = drwEmailAddress.ItemArray[3].ToString(); // Get their Name strEmailToName = drwEmailAddress.ItemArray[0].ToString() + " " + drwEmailAddress.ItemArray[1].ToString(); // get userid int userID = 0; Int32.TryParse(drwEmailAddress["userID"].ToString(), out userID); objEmail.SetEmailBody(strEmailBodyTemplate, userID, "", "", "", "", "", "", "", ""); strSubject = objEmail.emailHeaderSub(strSubject); // Attempt to send them an email objEmail.SendEmail(strEmailAddress, strEmailToName, strEmailFromEmail, strEmailFromName, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, userID); strUsers += "\n\t" + strEmailToName; } } // send the administrator email string strAdminEmail = GetEmailBody(EmailReportType.Email_Incomplete_CPD_Administrator); objEmail.SetEmailBody(strAdminEmail, UserContext.UserID, "", "", "", strUsers, "", "", "", ""); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); // done this.plhReportResults.Visible=false; this.plhComplete.Visible=true; }
/// <summary> /// Item Command /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void grdPagination_ItemCommand(object source, DataGridCommandEventArgs e) { // If user is resending the email if (e.CommandName.ToLower() == "resend") { BusinessServices.User objUser; int emailID = 0; // get the user FROM info (which is the currently logged in user) objUser = new BusinessServices.User(); DataTable dtbCurrentUser = objUser.GetUser(UserContext.UserID); // get the email ID and retrieve this email from the database Int32.TryParse(e.CommandArgument.ToString(), out emailID); BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.Search(emailID, UserContext.UserData.OrgID); // only get the first (since there SHOULD only be one emailid) if (dtbEmails.Rows.Count != 0) { // get the user id for this email int userID = 0; Int32.TryParse(dtbEmails.Rows[0]["userid"].ToString(), out userID); string strEmailTo = dtbEmails.Rows[0]["toemail"].ToString(); string strNameTo = null; if (userID == 0) { // get the To name strNameTo = dtbEmails.Rows[0]["toname"] == null ? null : dtbEmails.Rows[0]["toname"].ToString(); } else { DataTable dtbUser = objUser.GetUser(userID); strNameTo = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); } string strEmailFrom = dtbCurrentUser.Rows[0]["email"].ToString(); string strNameFrom = dtbCurrentUser.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUser.Rows[0]["LastName"].ToString(); string strBody = dtbEmails.Rows[0]["body"].ToString(); string strSubject = dtbEmails.Rows[0]["subject"].ToString(); // no need to do the subs here as its just trying to resend the email. objEmail.setUserCopyEmailBody(strBody); objEmail.SendEmail(strEmailTo, strNameTo, strEmailFrom, strNameFrom, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, userID); this.lblMessage.Text = ResourceManager.GetString("lblMessage.EmailSent"); this.lblMessage.Visible = true; this.lblMessage.CssClass = "SuccessMessage"; } } }
/// <summary> /// Get Pagination Data /// </summary> /// <returns></returns> private DataView GetPaginationData() { //Customize, and return DataView DateTime dteDateFrom, dteDateTo; string strToEmail, strSubject, strBody; int intFromYear, intFromMonth, intFromDay; int intToYear, intToMonth, intToDay; intFromYear = int.Parse(this.cboFromYear.SelectedValue); intFromMonth = int.Parse(this.cboFromMonth.SelectedValue); intFromDay = int.Parse(this.cboFromDay.SelectedValue); intToYear = int.Parse(this.cboToYear.SelectedValue); intToMonth = int.Parse(this.cboToMonth.SelectedValue); intToDay = int.Parse(this.cboToDay.SelectedValue); try { dteDateFrom = new DateTime(intFromYear, intFromMonth, intFromDay); dteDateTo = new DateTime(intToYear, intToMonth, intToDay); } catch (ArgumentOutOfRangeException) { throw new BusinessServiceException(ResourceManager.GetString("InvalidDateRange")); } strToEmail = this.txtToEmail.Text; strSubject = this.txtSubject.Text; strBody = this.txtBody.Text; BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.Search(dteDateFrom, dteDateTo, strToEmail, strSubject, strBody, UserContext.UserData.OrgID); if (dtbEmails.Rows.Count == 0) { this.lblSearchMessage.Text = ResourceManager.GetString("lblSearchMessage.Non"); //"No Matching Emails Found"; this.lblSearchMessage.CssClass = "WarningMessage"; this.lblSearchMessage.Visible = true; this.tblPagination.Visible = false; } else { this.lblSearchMessage.Visible = false; this.tblPagination.Visible = true; } return(dtbEmails.DefaultView); }
protected void rptEmailList_ItemCommand(object sender, RepeaterCommandEventArgs e) { if (e.CommandName == "ResendEmail") { BusinessServices.User objUser; int intOrganisationID, emailID; // get the user TO info objUser = new BusinessServices.User(); DataTable dtbUser = objUser.GetUser(this.m_intUserID); intOrganisationID = (int)dtbUser.Rows[0]["OrganisationID"]; // get the user FROM info DataTable dtbCurrentUser = objUser.GetUser(UserContext.UserID); // convert the emailID text to int bool result = Int32.TryParse(e.CommandArgument.ToString(), out emailID); if (result) { BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.Search(emailID, intOrganisationID); if (dtbEmails.Rows.Count != 0) { string strEmailTo = dtbEmails.Rows[0]["toemail"].ToString(); string strNameTo = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); string strEmailFrom = dtbCurrentUser.Rows[0]["email"].ToString(); string strNameFrom = dtbCurrentUser.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUser.Rows[0]["LastName"].ToString(); string strBody = dtbEmails.Rows[0]["body"].ToString(); string strSubject = dtbEmails.Rows[0]["subject"].ToString(); objEmail.setUserCopyEmailBody(strBody); objEmail.SendEmail(strEmailTo, strNameTo, strEmailFrom, strNameFrom, null, null, strSubject, ApplicationSettings.MailServer, intOrganisationID, UserContext.UserID); this.lblMessage.Text = ResourceManager.GetString("lblMessage.EmailSent"); this.lblMessage.Visible = true; this.lblMessage.CssClass = "SuccessMessage"; } } } }
/// <summary> /// Load data the page is first loaded /// </summary> private void LoadData() { DateTime dteDateFrom, dteDateTo; BusinessServices.User objUser; DataTable dtbUser; string strName, strEmail; int intOrganisationID; objUser = new BusinessServices.User(); dtbUser = objUser.GetUser(this.m_intUserID); strName = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); strEmail = dtbUser.Rows[0]["Email"].ToString(); intOrganisationID = (int)dtbUser.Rows[0]["OrganisationID"]; // set to the past to search for emails from the beginning // maybe there is a better way to set to the beginning but right now use the hardcoded values dteDateFrom = new DateTime(1990, 1, 1); dteDateTo = DateTime.Now; BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.SearchByUserID(this.m_intUserID, intOrganisationID); if (dtbEmails.Rows.Count == 0) { this.lblMessage.Text = ResourceManager.GetString("lblMessage.NoEmails"); this.lblMessage.CssClass = "WarningMessage"; this.lblMessage.Visible = true; } else { this.rptEmailList.DataSource = dtbEmails; this.rptEmailList.DataBind(); this.lblMessage.Visible = false; } }
public void StatusResetError(string strBody) { BusinessServices.Email objEmail = new BusinessServices.Email(); objEmail.SendEmail(ApplicationSettings.SupportEmail, "Developer Team", ApplicationSettings.SupportEmail, "Developer Team", null, null, "Error in Adaptive Status Reset from Salt Web Application", strBody, ApplicationSettings.MailServer); }
protected void btnServiceToggle_Click(object sender, EventArgs e) { try { BusinessServices.AppConfig ac = new BusinessServices.AppConfig(); BusinessServices.Email em = new BusinessServices.Email(); DataTable dt = ac.getMailServices(); String[] strArr; ServiceController scQueueMail = null; ServiceController scQueueReports = null; ServiceController scSendMail = null; foreach (DataRow dr in dt.Rows) { strArr = dr.ItemArray[1].ToString().Split(';'); if (dr.ItemArray[0].Equals("MailService_QueueMail")) { scQueueMail = new ServiceController(strArr[1], strArr[0]); } else if (dr.ItemArray[0].Equals("MailService_QueueReports")) { scQueueReports = new ServiceController(strArr[1], strArr[0]); } else if (dr.ItemArray[0].Equals("MailService_SendMail")) { scSendMail = new ServiceController(strArr[1], strArr[0]); } } //String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;// used for debugging // if its stopped then start it if (scSendMail.Status == ServiceControllerStatus.Stopped) { em.purgeAutoEmails(); // set the send mail flag to allow emails to be sent ac.Update("SEND_AUTO_EMAILS", "YES"); scSendMail.Start(); scSendMail.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10)); scSendMail.Refresh(); } // if its started then stop it else if (scSendMail.Status == ServiceControllerStatus.Running) { em.purgeAutoEmails(); // set the send mail flag to stop emails from being sent ac.Update("SEND_AUTO_EMAILS", "NO"); // restart report queuing restartService(scQueueReports); scSendMail.Stop(); scSendMail.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10)); scSendMail.Refresh(); // restart mail queuing service restartService(scQueueMail); } //username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; setButtonLabel(); } catch (Exception ex) { ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "Service Control", "Panic button pressed", ex.Message); } }
/// <summary> /// Compiles the list of users to which the email should be sent, /// and attempts to send it to that list + anyone on the CC list /// + the current user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSendEmail_Click(object sender, System.EventArgs e) { string strUnitIDs = ""; string strUserIDs = ""; lblError.Text = ""; try { // Get selected units BusinessServices.Unit objUnit = new BusinessServices.Unit(); string[] astrUnitIDs = astrUnitIDs = objUnit.ReturnAdministrableUnitsByUserID(UserContext.UserID, UserContext.UserData.OrgID, trvUnitsSelector.GetSelectedValues()); foreach (string strUnit in astrUnitIDs) { strUnitIDs += strUnit + ","; } if (strUnitIDs.Length > 0) { strUnitIDs = strUnitIDs.Substring(0, strUnitIDs.Length - 1); } // Get users DataTable dtbResults = new Email().GetUsersToEmail(UserContext.UserData.OrgID, strUnitIDs); foreach (DataRow drwUser in dtbResults.Rows) { strUserIDs += drwUser.ItemArray[0].ToString() + ","; } if (strUserIDs.Length > 0) { strUserIDs = strUserIDs.Substring(0, strUserIDs.Length - 1); } // Validate that the user has a valid recipient, subject and body. if (strUserIDs.Length > 0 && this.txtEmailSubject.Text.Length > 0 && this.txtEmailBody.Text.Length > 0) { // Config BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig(); DataTable dtbAppConfig = objAppConfig.GetList(); this.lblError.Text = ""; // Email setup BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); string strEmailFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strEmailFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); string strEmailSubject = this.txtEmailSubject.Text; string strUsers = "\n\nSent To:"; BusinessServices.Email objEmail = new BusinessServices.Email(); // target users string strEmailToName = ""; string strEmailToEmail = ""; DataTable dtbEmailAddresses = objUser.GetEmails(strUserIDs); foreach (DataRow drwEmailAddress in dtbEmailAddresses.Rows) { strEmailToEmail = drwEmailAddress.ItemArray[3].ToString(); strEmailToName = drwEmailAddress.ItemArray[0].ToString() + " " + drwEmailAddress.ItemArray[1].ToString(); int intUserId = Int32.Parse(drwEmailAddress.ItemArray[1].ToString()); objEmail.SetEmailBody(this.txtEmailBody.Text, intUserId, "", "", "", "", "", "", "", ""); strEmailSubject = objEmail.emailHeaderSub(strEmailSubject); objEmail.SendEmail(strEmailToEmail, strEmailToName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, intUserId); // accumulate user list to append to current user email strUsers += "\n\t" + strEmailToName; } // CC list. string strEmailCCName = ""; strUsers += "\n\nCC:"; foreach (string addr in this.txtCC.Text.Split(new char[] { ',', ';' })) { string strEmailCCEmail = addr.Trim(); if (strEmailCCEmail != "") { try { objEmail.SendEmail(strEmailCCEmail, strEmailCCName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, 0); strUsers += "\n\t" + strEmailCCEmail; } catch (Exception) { objEmail.setCCSendError(strEmailCCEmail); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, "Error sending mail to CC recipient", ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); } } } // copy to Current user objEmail.setUserCopyEmailBody(this.txtEmailBody.Text + strUsers); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); this.plhEditEmail.Visible = false; this.plhComplete.Visible = true; } else { lblError.Text = ResourceManager.GetString("lblError.OneRecip"); //"To send an email you must have at least one recipient, an email subject and an email body."; this.lblError.CssClass = "WarningMessage"; } } catch (Exception ex) { //Catch and throw error ErrorLog objError = new ErrorLog(ex, ErrorLevel.High, "EmailUsers.aspx.cs", "btnSendEmail_Click", "General error occurred attempting to send email"); throw (ex); } }
public void RecoverClick() { string strEmail = txtEmail.Text; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbUser = objUser.GetDetailsByEmailAndDomain(strEmail, HttpContext.Current.Request.Url.Host.ToString()); //DataTable dtbUser = objUser.GetDetailsByEmailAndDomain(strEmail, "demo.saltcompliance.com"); if (dtbUser.Rows.Count > 0 && Convert.ToBoolean(dtbUser.Rows[0]["Active"])) { // found user - gather details string strFirstName = dtbUser.Rows[0]["FirstName"].ToString(); string strLastName = dtbUser.Rows[0]["LastName"].ToString(); string strUserName = dtbUser.Rows[0]["UserName"].ToString(); string strPassword = dtbUser.Rows[0]["Password"].ToString(); string strUserId = dtbUser.Rows[0]["UserID"].ToString(); //Password encryption code string inputString = strPassword + DateTime.Now; SHA256 sha256 = SHA256Managed.Create(); byte[] bytes = Encoding.UTF8.GetBytes(inputString); byte[] hash = sha256.ComputeHash(bytes); string encryptedPassword = GetStringFromHash(hash); //Insert code for SP to insert new encrypted password objUser.UpdateEncryptedPassword(strUserName, encryptedPassword); string strFromName = ApplicationSettings.AppName; string strFromEmail = ApplicationSettings.SupportEmail; BusinessServices.Email objEmail = new BusinessServices.Email(); string strHREF = ""; string RedirectionCheck = Request.QueryString["Rdct"]; string strBody = ""; DataTable dtbOrgDisablePassword; string strDisabledpass = ""; dtbOrgDisablePassword = objUser.GetUserOrganisationPasswordLock(HttpContext.Current.Request.Url.Authority.ToString()); //dtbOrgDisablePassword = objUser.GetUserOrganisationPasswordLock("demo.saltcompliance.com"); if (dtbOrgDisablePassword.Rows.Count > 0) { if (dtbOrgDisablePassword.Rows[0]["PasswordLockout"].ToString().Trim().ToLower() == "true") { strDisabledpass = "******"; } else { strDisabledpass = ""; } } if (strDisabledpass == "Disabled") { strHREF = ""; strBody = GetBodyUniqueURL(strFirstName, strLastName, strUserName, strPassword, strUserId, encryptedPassword, strHREF); } else if (RedirectionCheck == "UniqueURL") { //strHREF = "http://localhost:51864/Default.aspx?AutoLgnUSID=" + strUserId + "&AutoLgnPass="******"https://" + HttpContext.Current.Request.Url.Host + "/Default.aspx?AutoLgnUSID=" + strUserId + "&AutoLgnPass="******"https://" + HttpContext.Current.Request.Url.Host + "/ChangePassword.aspx?UID=" + strUserId + "&P=" + encryptedPassword; strBody = GetBody(strFirstName, strLastName, strUserName, strPassword, strUserId, encryptedPassword, strHREF); } try { // Found user send email objEmail.SendEmail(strEmail, strFirstName + " " + strLastName, strFromEmail, strFromName, null, null, ResourceManager.GetString("EmailSubject"), strBody, ApplicationSettings.MailServer); lblMessage.Text = String.Format(ResourceManager.GetString("lblMessage.Sent"), strEmail); //"Login Information has been sent to:<BR>" + strEmail; lblMessage.CssClass = "WarningMessage"; btnRecover.Visible = false; txtEmail.Visible = false; lblText.Visible = false; } catch (Exception ex) { // Found user but unable to send email lblMessage.Text = ResourceManager.GetString("UserNotFound") + ex.Message; lblMessage.CssClass = "WarningMessage"; btnRecover.Visible = false; txtEmail.Visible = false; } } else { // inactive user : user not found lblMessage.Text = ResourceManager.GetString(dtbUser.Rows.Count > 0 ? "lblMessage.Inactive" : "lblMessage.NotFound"); lblMessage.CssClass = "WarningMessage"; } }