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) { } }
private bool SendMail(UserVo userVo) { Emailer emailer = new Emailer(); EmailMessage email = new EmailMessage(); advisorVo = (AdvisorVo)Session["advisorVo"]; 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; email.GetCustomerAccountMail(userVo.LoginId, Encryption.Decrypt(userVo.Password), 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); //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 slected 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); }
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); }