private void SendMail(UserVo userVo) { Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); try { email.To.Add(userVo.Email); string name = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; if (btnGenerate.Text == "Reset Password") { email.GetResetPasswordMail(userVo.LoginId, Encryption.Decrypt(userVo.Password), name); } else { email.GetCustomerAccountMail(userVo.LoginId, Encryption.Decrypt(userVo.Password), name); } emailer.SendMail(email); } catch (Exception ex) { } }
protected void btnGenerate_Click(object sender, EventArgs e) { AdvisorPreferenceVo advisorPreferenceVo = new AdvisorPreferenceVo(); advisorVo = (AdvisorVo)Session["advisorVo"]; if (Session["AdvisorPreferenceVo"] != null) { advisorPreferenceVo = (AdvisorPreferenceVo)Session["AdvisorPreferenceVo"]; } int selectedRecords = 0; string statusMessage = string.Empty; advisorVo = (AdvisorVo)Session["advisorVo"]; string logoPath = string.Empty; if (Page.IsValid) { //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "leftpane", "$.colorbox({width: '700px', overlayClose: false, inline: true, href: '#LoadImage'});", true); try { foreach (GridDataItem gvr in gvUserMgt.Items) { if (((CheckBox)gvr.FindControl("cbRecons")).Checked == true) { selectedRecords++; int selectedRow = gvr.ItemIndex + 1; string Phone1Details = string.Empty, phone2Details = string.Empty, phone3Details = string.Empty, PhoneNumber = string.Empty; userId = int.Parse((gvUserMgt.MasterTableView.DataKeyValues[selectedRow - 1]["UserId"].ToString())); Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); string hassedPassword = string.Empty; string saltValue = string.Empty; encryption = new OneWayEncryption(); Random r = new Random(); userVo = userBo.GetUserDetails(userId); string password = r.Next(20000, 100000).ToString(); encryption.GetHashAndSaltString(password, out hassedPassword, out saltValue); userVo.Password = hassedPassword; userVo.PasswordSaltValue = saltValue; userVo.OriginalPassword = password; userVo.IsTempPassword = 1; userBo.UpdateUser(userVo); string userName = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; email.GetResetPasswordMail(userVo.LoginId, password, userName); email.Subject = email.Subject.Replace("WealthERP", advisorVo.OrganizationName); email.Subject = email.Subject.Replace("MoneyTouch", advisorVo.OrganizationName); //email.Body = email.Body.Replace("[ORGANIZATION]", advisorVo.OrganizationName); email.Body = email.Body.Replace("[CUSTOMER_NAME]", userVo.FirstName); if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Citrus") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } email.Body = email.Body.Replace("[CONTACTPERSON]", advisorVo.ContactPersonFirstName + " " + advisorVo.ContactPersonMiddleName + " " + advisorVo.ContactPersonLastName); if (!string.IsNullOrEmpty(advisorVo.Designation)) { email.Body = email.Body.Replace("[DESIGNATION]", advisorVo.Designation.Trim()); } else { email.Body = email.Body.Replace("[DESIGNATION]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Phone1Number.ToString()) || !string.IsNullOrEmpty(advisorVo.Phone2Number.ToString()) || !string.IsNullOrEmpty(advisorVo.Phone3Number.ToString())) { if (!string.IsNullOrEmpty(advisorVo.Phone1Isd) && !string.IsNullOrEmpty(advisorVo.Phone1Std) && advisorVo.Phone1Number > 1) { Phone1Details = advisorVo.Phone1Isd.ToString() + "-" + advisorVo.Phone1Std.ToString() + "-" + advisorVo.Phone1Number.ToString(); } else if (!string.IsNullOrEmpty(advisorVo.Phone1Isd) && !string.IsNullOrEmpty(advisorVo.Phone1Std) && advisorVo.Phone1Number > 1) { Phone1Details = advisorVo.Phone1Std.ToString() + "-" + advisorVo.Phone1Number.ToString(); } else if (!string.IsNullOrEmpty(advisorVo.Phone1Isd) && !string.IsNullOrEmpty(advisorVo.Phone1Std) && advisorVo.Phone1Number > 1) { Phone1Details = advisorVo.Phone1Isd.ToString() + "-" + advisorVo.Phone1Number.ToString(); } else if (string.IsNullOrEmpty(advisorVo.Phone1Isd) && string.IsNullOrEmpty(advisorVo.Phone1Std) && advisorVo.Phone1Number > 1) { Phone1Details = advisorVo.Phone1Number.ToString(); } if (!string.IsNullOrEmpty(advisorVo.Phone2Isd) && !string.IsNullOrEmpty(advisorVo.Phone2Std) && advisorVo.Phone2Number > 1) { phone2Details = advisorVo.Phone2Isd.ToString() + "-" + advisorVo.Phone2Std.ToString() + "-" + advisorVo.Phone2Number.ToString(); } else if (string.IsNullOrEmpty(advisorVo.Phone2Isd) && !string.IsNullOrEmpty(advisorVo.Phone2Std) && advisorVo.Phone2Number > 1) { phone2Details = advisorVo.Phone2Std.ToString() + "-" + advisorVo.Phone2Number.ToString(); } else if (!string.IsNullOrEmpty(advisorVo.Phone2Isd) && string.IsNullOrEmpty(advisorVo.Phone2Std) && advisorVo.Phone2Number > 1) { phone2Details = advisorVo.Phone2Isd.ToString() + "-" + advisorVo.Phone2Number.ToString(); } else if (string.IsNullOrEmpty(advisorVo.Phone2Isd) && string.IsNullOrEmpty(advisorVo.Phone2Std) && advisorVo.Phone2Number > 1) { phone2Details = advisorVo.Phone2Number.ToString(); } if (!string.IsNullOrEmpty(advisorVo.Phone3Isd) && !string.IsNullOrEmpty(advisorVo.Phone3Std) && advisorVo.Phone3Number > 1) { phone3Details = advisorVo.Phone3Isd.ToString() + "-" + advisorVo.Phone3Std.ToString() + "-" + advisorVo.Phone3Number.ToString(); } else if (string.IsNullOrEmpty(advisorVo.Phone3Isd) && !string.IsNullOrEmpty(advisorVo.Phone3Std) && advisorVo.Phone3Number > 1) { phone3Details = advisorVo.Phone3Std.ToString() + "-" + advisorVo.Phone3Number.ToString(); } else if (!string.IsNullOrEmpty(advisorVo.Phone3Isd) && string.IsNullOrEmpty(advisorVo.Phone3Std) && advisorVo.Phone3Number > 1) { phone3Details = advisorVo.Phone3Isd.ToString() + "-" + advisorVo.Phone3Number.ToString(); } else if (string.IsNullOrEmpty(advisorVo.Phone3Isd) && string.IsNullOrEmpty(advisorVo.Phone3Std) && advisorVo.Phone3Number > 1) { phone3Details = advisorVo.Phone3Number.ToString(); } if (!string.IsNullOrEmpty(Phone1Details) && !string.IsNullOrEmpty(phone2Details) && !string.IsNullOrEmpty(phone3Details)) { PhoneNumber = Phone1Details + "/" + phone2Details + "/" + phone3Details; } else if (!string.IsNullOrEmpty(Phone1Details) && !string.IsNullOrEmpty(phone2Details) && string.IsNullOrEmpty(phone3Details)) { PhoneNumber = Phone1Details + "/" + phone2Details; } else if (string.IsNullOrEmpty(Phone1Details) && !string.IsNullOrEmpty(phone2Details) && !string.IsNullOrEmpty(phone3Details)) { PhoneNumber = phone2Details + "/" + phone3Details; } else if (!string.IsNullOrEmpty(Phone1Details) && string.IsNullOrEmpty(phone2Details) && !string.IsNullOrEmpty(phone3Details)) { PhoneNumber = Phone1Details + "/" + phone3Details; } else if (!string.IsNullOrEmpty(Phone1Details) && string.IsNullOrEmpty(phone2Details) && string.IsNullOrEmpty(phone3Details)) { PhoneNumber = Phone1Details; } else if (string.IsNullOrEmpty(Phone1Details) && !string.IsNullOrEmpty(phone2Details) && string.IsNullOrEmpty(phone3Details)) { PhoneNumber = phone2Details; } else if (string.IsNullOrEmpty(Phone1Details) && string.IsNullOrEmpty(phone2Details) && !string.IsNullOrEmpty(phone3Details)) { PhoneNumber = phone3Details; } email.Body = email.Body.Replace("[PHONE]", PhoneNumber); } else { email.Body = email.Body.Replace("[PHONE]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Email)) { email.Body = email.Body.Replace("[EMAIL]", advisorVo.Email.Trim()); } else { email.Body = email.Body.Replace("[EMAIL]", string.Empty); } email.Body = email.Body.Replace("[LOGO]", "<img src='cid:HDIImage' alt='Logo'>"); System.Net.Mail.AlternateView htmlView; System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Text view", null, "text/plain"); //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(hidBody.Value.Trim() + "<image src=cid:HDIImage>", null, "text/html"); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body " + "style='font-family:Tahoma, Arial; font-size: 10pt;'><p>" + email.Body + "</p></body></html>", null, "text/html"); //Add image to HTML version if (advisorVo != null) { logoPath = "~/Images/" + advisorVo.LogoPath; } if (!File.Exists(Server.MapPath(logoPath))) { logoPath = "~/Images/spacer.png"; } //System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath("~/Images/") + @"\3DSYRW_4009.JPG", "image/jpeg"); System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath(logoPath), "image/jpeg"); imageResource.ContentId = "HDIImage"; htmlView.LinkedResources.Add(imageResource); //Add two views to message. email.AlternateViews.Add(plainTextView); email.AlternateViews.Add(htmlView); email.To.Add(userVo.Email); AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo(); int rmId = Convert.ToInt32(ViewState["rmId"]); AdviserStaffSMTPVo adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(rmId); if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) { if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "MoneyTouch") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } } } bool isMailSent = false; if (userBo.UpdateUser(userVo)) { isMailSent = emailer.SendMail(email); } if (isMailSent) { statusMessage = "Credentials have been reset and sent to selected user"; tblMessage.Visible = true; ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; SuccessMsg.Visible = true; } else { statusMessage = "An error occurred while sending mail to selected user"; tblMessage.Visible = true; ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; SuccessMsg.Visible = false; } } } //if (selectedRecords == 0) //statusMessage = "Please select RM to send Password"; ErrorMessage.Visible = false; } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "RMCustomerUserDetails.ascx:btnGenerate_Click()"); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } } }
private bool SendMail(UserVo userVo, bool isNewLogin) { Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); AdvisorPreferenceVo advisorPreferenceVo = new AdvisorPreferenceVo(); advisorVo = (AdvisorVo)Session["advisorVo"]; if (Session["AdvisorPreferenceVo"] != null) { advisorPreferenceVo = (AdvisorPreferenceVo)Session["AdvisorPreferenceVo"]; } string logoPath = string.Empty; bool isMailSent = false; bool isEmailIdBlank = false; try { UserVo uservo = (UserVo)Session["userVo"]; AdvisorStaffBo adviserstaffbo = new AdvisorStaffBo(); //Get SMTP settings of admin if configured. RMVo advrm = new RMVo(); advrm = adviserstaffbo.GetAdvisorStaff(uservo.UserId); AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo(); AdviserStaffSMTPVo adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(advrm.RMId); //Get the mail contents if (userVo.Email.Trim() != string.Empty) { email.To.Add(userVo.Email); string name = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; if (isNewLogin) { email.GetCustomerAccountMail(userVo.LoginId, userVo.OriginalPassword, name); } else { email.GetResetPasswordMail(userVo.LoginId, userVo.OriginalPassword, name); } email.Subject = email.Subject.Replace("WealthERP", advisorVo.OrganizationName); email.Subject = email.Subject.Replace("MoneyTouch", advisorVo.OrganizationName); email.Body = email.Body.Replace("[ORGANIZATION]", advisorVo.OrganizationName); email.Body = email.Body.Replace("[CUSTOMER_NAME]", userVo.FirstName); if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Citrus") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } email.Body = email.Body.Replace("[CONTACTPERSON]", advisorVo.ContactPersonFirstName + " " + advisorVo.ContactPersonMiddleName + " " + advisorVo.ContactPersonLastName); if (!string.IsNullOrEmpty(advisorVo.Designation)) { email.Body = email.Body.Replace("[DESIGNATION]", advisorVo.Designation); } else { email.Body = email.Body.Replace("[DESIGNATION]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Phone1Number.ToString())) { email.Body = email.Body.Replace("[PHONE]", advisorVo.Phone1Std.ToString() + "-" + advisorVo.Phone1Number.ToString()); } else { email.Body = email.Body.Replace("[PHONE]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Email)) { email.Body = email.Body.Replace("[EMAIL]", advisorVo.Email); } else { email.Body = email.Body.Replace("[EMAIL]", string.Empty); } email.Body = email.Body.Replace("[LOGO]", "<img src='cid:HDIImage' alt='Logo'>"); System.Net.Mail.AlternateView htmlView; System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Text view", null, "text/plain"); //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(hidBody.Value.Trim() + "<image src=cid:HDIImage>", null, "text/html"); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body " + "style='font-family:Tahoma, Arial; font-size: 10pt;'><p>" + email.Body + "</p></body></html>", null, "text/html"); //Add image to HTML version if (advisorVo != null) { logoPath = "~/Images/" + advisorVo.LogoPath; } if (!File.Exists(Server.MapPath(logoPath))) { logoPath = "~/Images/spacer.png"; } //System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath("~/Images/") + @"\3DSYRW_4009.JPG", "image/jpeg"); System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath(logoPath), "image/jpeg"); imageResource.ContentId = "HDIImage"; htmlView.LinkedResources.Add(imageResource); //Add two views to message. email.AlternateViews.Add(plainTextView); email.AlternateViews.Add(htmlView); //Send message //System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); //Assign SMTP Credentials if configured. if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) { if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "MoneyTouch") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } } } //Sending mail... isMailSent = emailer.SendMail(email); } else { isEmailIdBlank = true; } if (isEmailIdBlank) { if (string.IsNullOrEmpty(statusMessage)) { statusMessage = "No email Id specified for selected User"; tblMessage.Visible = true; ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; SuccessMsg.Visible = false; } else { statusMessage = statusMessage + " and some selected User don't have E-mail id"; tblMessage.Visible = true; ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; SuccessMsg.Visible = false; } } else if (isMailSent) { if (string.IsNullOrEmpty(statusMessage)) { statusMessage = "Credentials have been sent to selected User"; tblMessage.Visible = true; ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; SuccessMsg.Visible = true; } else if (statusMessage == "No email Id specified for slected User") { statusMessage = "some selected User don't have E-mail id and Credentials have been sent sucessfully to rest of User"; statusMessage = "Credentials have been sent to selected User"; tblMessage.Visible = true; ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; SuccessMsg.Visible = true; } else { tblMessage.Visible = true; ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; SuccessMsg.Visible = true; } } else { statusMessage = "An error occurred while sending mail .. "; tblMessage.Visible = true; ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; SuccessMsg.Visible = false; } } catch (Exception ex) { } return(isMailSent); }
protected void btnSendEmailToIFF_Click(object sender, EventArgs e) { int selectedRecords = 0; string statusMessage = string.Empty; advisorVo = (AdvisorVo)Session["advisorVo"]; AdvisorBo advisorBo = new AdvisorBo(); RMVo rmVo = new RMVo(); AdvisorStaffBo advisorStaffBo = new AdvisorStaffBo(); Random r = new Random(); string logoPath = string.Empty; if (Page.IsValid) { try { foreach (GridViewRow gvr in gvIFFUsers.Rows) { if (((CheckBox)gvr.FindControl("chkBoxChild")).Checked == true) { selectedRecords++; userId = int.Parse(gvIFFUsers.DataKeys[gvr.RowIndex].Value.ToString()); advisorVo = advisorBo.GetAdvisorUser(userId); rmVo = advisorStaffBo.GetAdvisorStaff(userId); Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); string hassedPassword = string.Empty; string saltValue = string.Empty; string password = r.Next(20000, 100000).ToString(); userVo = userBo.GetUserDetails(userId); string userName = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; encryption.GetHashAndSaltString(password, out hassedPassword, out saltValue); userVo.Password = hassedPassword; userVo.PasswordSaltValue = saltValue; userVo.OriginalPassword = password; userVo.IsTempPassword = 1; email.GetResetPasswordMail(userVo.LoginId, password, userName); //email.Subject = email.Subject.Replace("WealthERP", advisorVo.OrganizationName); //email.Subject = email.Subject.Replace("MoneyTouch", advisorVo.OrganizationName); //email.Body = email.Body.Replace("[ORGANIZATION]", advisorVo.OrganizationName); email.To.Add(userVo.Email); AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo(); //int rmId = Convert.ToInt32(ViewState["rmId"]); AdviserStaffSMTPVo adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(1000); //adviserStaffSMTPVo.HostServer = ""; if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; //email.Subject = email.Subject.Replace("WealthERP", advisorVo.OrganizationName); //email.Subject = email.Subject.Replace("MoneyTouch", advisorVo.OrganizationName); email.Body = email.Body.Replace("[ORGANIZATION]", "WealthERP Team"); if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.Body = email.Body.Replace("[WEBSITE]", "https://app.wealtherp.com/"); } email.Body = email.Body.Replace("[CONTACTPERSON]", "Customer Care"); email.Body = email.Body.Replace("[DESIGNATION]", "Team WealthERP"); email.Body = email.Body.Replace("[PHONE]", "+91 9663305249 <br/>Skype: custcare.ampsys"); email.Body = email.Body.Replace("[EMAIL]", "*****@*****.**"); email.Body = email.Body.Replace("[LOGO]", "<img src='cid:HDIImage' alt='Logo'>"); System.Net.Mail.AlternateView htmlView; System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Text view", null, "text/plain"); //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(hidBody.Value.Trim() + "<image src=cid:HDIImage>", null, "text/html"); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body " + "style='font-family:Tahoma, Arial; font-size: 10pt;'><p>" + email.Body + "</p></body></html>", null, "text/html"); //Add image to HTML version logoPath = "~/Images/WealthERP.jpf"; if (!File.Exists(Server.MapPath(logoPath))) { logoPath = "~/Images/spacer.png"; } //System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath("~/Images/") + @"\3DSYRW_4009.JPG", "image/jpeg"); System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath(logoPath), "image/jpeg"); imageResource.ContentId = "HDIImage"; htmlView.LinkedResources.Add(imageResource); //Add two views to message. email.AlternateViews.Add(plainTextView); email.AlternateViews.Add(htmlView); //Send message //System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); //Assign SMTP Credentials if configured. if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) { if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.From = new MailAddress(emailer.smtpUserName, "WealthERP Team"); } } } //if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) //{ // if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") // { // email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); // } // else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "MoneyTouch") // { // email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); // } //} } bool isMailSent = false; if (userBo.UpdateUser(userVo)) { isMailSent = emailer.SendMail(email); } if (isMailSent) { statusMessage = "Credentials have been reset & sent to selected Adviser"; tblMessage.Visible = true; tblErrorMassage.Visible = false; //ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; //SuccessMsg.Visible = true; } else { statusMessage = "An error occurred while sending mail to selected Adviser"; tblMessage.Visible = false; tblErrorMassage.Visible = true; //ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; //SuccessMsg.Visible = false; } } } tblErrorMassage.Visible = false; //ErrorMessage.Visible = false; } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "RMCustomerUserDetails.ascx:btnGenerate_Click()"); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { advisorVo = (AdvisorVo)Session["advisorVo"]; if (Session["AdvisorPreferenceVo"] != null) { advisorPreferenceVo = (AdvisorPreferenceVo)Session["AdvisorPreferenceVo"]; } // userVo = userBo.GetUser(txtLoginId.Text); userVo = userBo.GetUserReset(txtLoginId.Text, txtEmail.Text, TxtPan.Text); if (userVo != null) { advisorVo = advisorBo.GetAssociateAdviserUser(userVo.UserId); } Random r = new Random(); OneWayEncryption encryption; encryption = new OneWayEncryption(); bool isSuccess = false; string logoPath = string.Empty; string statusMessage = string.Empty; ScriptManager script = new ScriptManager(); if (userVo != null) // && userVo.Email == txtEmail.Text ) { string hassedPassword = string.Empty; string saltValue = string.Empty; string password = r.Next(20000, 100000).ToString(); //userVo = userBo.GetUserDetails(userId); // string userName = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; encryption.GetHashAndSaltString(password, out hassedPassword, out saltValue); userVo.Password = hassedPassword; userVo.PasswordSaltValue = saltValue; userVo.OriginalPassword = password; userVo.IsTempPassword = 1; // isSuccess = userBo.UpdateUser(userVo); isSuccess = userBo.UpdateUserReset(userVo); string userName = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName; email.GetResetPasswordMail(userVo.LoginId, password, userName); email.Subject = email.Subject.Replace("WealthERP", advisorVo.OrganizationName); email.Subject = email.Subject.Replace("MoneyTouch", advisorVo.OrganizationName); //email.Body = email.Body.Replace("[ORGANIZATION]", advisorVo.OrganizationName); email.Body = email.Body.Replace("[CUSTOMER_NAME]", userVo.FirstName); if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Citrus") { email.Body = email.Body.Replace("[WEBSITE]", advisorPreferenceVo.WebSiteDomainName); } email.Body = email.Body.Replace("[CONTACTPERSON]", advisorVo.ContactPersonFirstName + " " + advisorVo.ContactPersonMiddleName + " " + advisorVo.ContactPersonLastName); if (!string.IsNullOrEmpty(advisorVo.Designation)) { email.Body = email.Body.Replace("[DESIGNATION]", advisorVo.Designation.Trim()); } else { email.Body = email.Body.Replace("[DESIGNATION]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Phone1Number.ToString())) { email.Body = email.Body.Replace("[PHONE]", advisorVo.Phone1Std.ToString().Trim() + "-" + advisorVo.Phone1Number.ToString().Trim()); } else { email.Body = email.Body.Replace("[PHONE]", string.Empty); } if (!string.IsNullOrEmpty(advisorVo.Email)) { email.Body = email.Body.Replace("[EMAIL]", advisorVo.Email.Trim()); } else { email.Body = email.Body.Replace("[EMAIL]", string.Empty); } email.Body = email.Body.Replace("[LOGO]", "<img src='cid:HDIImage' alt='Logo'>"); System.Net.Mail.AlternateView htmlView; System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Text view", null, "text/plain"); //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(hidBody.Value.Trim() + "<image src=cid:HDIImage>", null, "text/html"); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body " + "style='font-family:Tahoma, Arial; font-size: 10pt;'><p>" + email.Body + "</p></body></html>", null, "text/html"); //Add image to HTML version if (advisorVo != null) { logoPath = "~/Images/" + advisorVo.LogoPath; } if (!File.Exists(Server.MapPath(logoPath))) { logoPath = "~/Images/spacer.png"; } //System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath("~/Images/") + @"\3DSYRW_4009.JPG", "image/jpeg"); System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(Server.MapPath(logoPath), "image/jpeg"); imageResource.ContentId = "HDIImage"; htmlView.LinkedResources.Add(imageResource); //Add two views to message. email.AlternateViews.Add(plainTextView); email.AlternateViews.Add(htmlView); email.To.Add(userVo.Email); AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo(); int rmId = userVo.rmid; AdviserStaffSMTPVo adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(rmId); if (adviserStaffSMTPVo.HostServer != null && adviserStaffSMTPVo.HostServer != string.Empty) { emailer.isDefaultCredentials = !Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired); if (!String.IsNullOrEmpty(adviserStaffSMTPVo.Password)) { emailer.smtpPassword = Encryption.Decrypt(adviserStaffSMTPVo.Password); } emailer.smtpPort = int.Parse(adviserStaffSMTPVo.Port); emailer.smtpServer = adviserStaffSMTPVo.HostServer; emailer.smtpUserName = adviserStaffSMTPVo.Email; if (Convert.ToBoolean(adviserStaffSMTPVo.IsAuthenticationRequired)) { if (ConfigurationSettings.AppSettings["HostName"].ToString() == "Wealtherp") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } else if (ConfigurationSettings.AppSettings["HostName"].ToString() == "MoneyTouch") { email.From = new MailAddress(emailer.smtpUserName, advisorVo.OrganizationName); } } } bool isMailSent = false; if (userBo.UpdateUser(userVo)) { isMailSent = emailer.SendMail(email); } if (isMailSent) { statusMessage = "Credentials have been reset and sent to your mail"; tblMessage.Visible = true; ErrorMessage.Visible = false; SuccessMsg.InnerText = statusMessage; SuccessMsg.Visible = true; txtLoginId.Text = ""; txtEmail.Text = ""; TxtPan.Text = ""; } } else { statusMessage = "Password has been not reset sucessfully"; tblMessage.Visible = true; ErrorMessage.Visible = true; ErrorMessage.InnerText = statusMessage; SuccessMsg.Visible = false; txtLoginId.Text = ""; txtEmail.Text = ""; TxtPan.Text = ""; } //if (isSuccess) //{ // tblMessage.Visible = true; // SuccessMsg.Visible = true; // ErrorMessage.Visible = false; // SuccessMsg.InnerText = "Password has been reset successfully..."; // txtLoginId.Text = ""; // txtEmail.Text = ""; // TxtPan.Text = ""; //} //else //{ // tblMessage.Visible = true; // SuccessMsg.Visible = false; // ErrorMessage.Visible = true; // ErrorMessage.InnerText = "An error occurred while reseting password."; //} }