Beispiel #1
0
        private bool SendMail()
        {
            Emailer      emailer = new Emailer();
            EmailMessage email   = new EmailMessage();

            string userName = rmUserVo.FirstName + " " + rmUserVo.MiddleName + " " + rmUserVo.LastName;

            email.GetAdviserRMAccountMail("rm" + Session["userId"].ToString(), Encryption.Decrypt(rmUserVo.Password), userName);
            email.To.Add(rmUserVo.Email);

            AdviserStaffSMTPBo adviserStaffSMTPBo = new AdviserStaffSMTPBo();
            AdviserStaffSMTPVo adviserStaffSMTPVo = adviserStaffSMTPBo.GetSMTPCredentials(advisorVo.advisorId);

            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))
                {
                    email.From = new MailAddress(emailer.smtpUserName, "WealthERP");
                }
            }
            bool isMailSent = emailer.SendMail(email);

            return(isMailSent);
        }
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            int    selectedRecords = 0;
            string statusMessage   = string.Empty;

            advisorVo = (AdvisorVo)Session["advisorVo"];


            if (Page.IsValid)
            {
                //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "leftpane", "$.colorbox({width: '700px', overlayClose: false, inline: true, href: '#LoadImage'});", true);
                try
                {
                    foreach (GridViewRow gvr in gvRMUsers.Rows)
                    {
                        if (((CheckBox)gvr.FindControl("chkBoxChild")).Checked == true)
                        {
                            selectedRecords++;

                            userId = int.Parse(gvRMUsers.DataKeys[gvr.RowIndex].Value.ToString());

                            Emailer      emailer = new Emailer();
                            EmailMessage email   = new EmailMessage();

                            userVo = userBo.GetUserDetails(userId);
                            string userName = userVo.FirstName + " " + userVo.MiddleName + " " + userVo.LastName;
                            email.GetAdviserRMAccountMail(userVo.LoginId, Encryption.Decrypt(userVo.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(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 = emailer.SendMail(email);

                            if (isMailSent)
                            {
                                statusMessage        = "Credentials have been 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;
                }
            }
        }