Esempio n. 1
0
        /// <summary>
        /// get cound email fromt id=start
        /// </summary>
        /// <param name="isInbox"></param>
        /// <param name="start"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IEnumerable<tblContact> fetchEmailList(bool isInbox, int start, int count)
        {
            IEnumerable<tblContact> lst = null;
            emailConf = control.getEmailConfig();
            if (isInbox)
            {
                lst = (from record in DB.tblContacts
                       orderby record.ID descending
                       where record.EmailTo == emailConf.Username
                       select record).Skip(start).Take(count);
            }
            else
            {
                lst = (from record in DB.tblContacts
                       orderby record.ID descending
                       where record.EmailFrom == emailConf.Username
                       select record).Skip(start).Take(count);
            }

            return lst;
        }
Esempio n. 2
0
        public EmailConf getEmailConfig()
        {
            EmailConf emailConf = new EmailConf();
            string strEmailConf = getValueString(CommonConstants.CF_EMAIL_CONFIG);
            //host - port; username; password; smtpserver - port;
            char[] delimiterChars = { '-', ';',};

            string[] emailConfDetails = strEmailConf.Split(delimiterChars);

            if (emailConfDetails.Count() > 5)
            {
                emailConf.Host = emailConfDetails[0];
                emailConf.HostPort = emailConfDetails[1];
                emailConf.Username = emailConfDetails[2];
                emailConf.Password = emailConfDetails[3];
                emailConf.SmptServer = emailConfDetails[4];
                emailConf.SmptPort = emailConfDetails[5];
            }

            return emailConf;
        }
Esempio n. 3
0
        private bool getEmailConfig()
        {
            emailConf = control.getEmailConfig();

            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// Gửi mật khẩu mới tới user
        /// </summary>
        /// <param name="_username"></param>
        /// <param name="_newPassword"></param>
        /// <param name="_email"></param>
        /// <returns></returns>
        public Boolean sendNewPassword(string _username, string _newPassword, string _email)
        {
            try
            {
                // Cập nhật mật khẩu
                Boolean isOK = updateUserPassword(_username, _newPassword);

                if (isOK)
                {
                    emailConf = control.getEmailConfig();

                    MailMessage message = new MailMessage();
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", emailConf.SmptServer);
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", emailConf.SmptPort);
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                    //Use 0 for anonymous
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", emailConf.Username);
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", emailConf.Password);
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
                    message.From = emailConf.Username;
                    message.To = _email;
                    message.Subject = "Mật khẩu mới tại " + control.getValueString(CommonConstants.CF_TITLE_ON_HEADER);
                    message.BodyFormat = MailFormat.Text;
                    message.BodyEncoding = Encoding.UTF8;
                    message.Body = "Tên đăng nhập: " + _username + "<br />" + "Mật khẩu: " + _newPassword;
                    SmtpMail.SmtpServer = emailConf.SmptServer + ":" + emailConf.SmptPort;

                    SmtpMail.Send(message);

                    contactDAO.insertEmail(CommonConstants.USER_SYSTEM,
                                                          emailConf.Username,
                                                          _email,
                                                          "Mật khẩu mới tại trang web" + control.getValueString(CommonConstants.CF_TITLE_ON_HEADER),
                                                          "Tên đăng nhập: " + _username + "<br />" + "Mật khẩu: " + _newPassword,
                                                          DateTime.Now);
                }
            }
            catch (Exception ex)
            {
                log.writeLog(DBHelper.strPathLogFile,
                              CommonConstants.USER_SYSTEM,
                              ex.Message);

                return false;
            }

            return true;
        }