Exemplo n.º 1
0
        public frmEmailSetting()
        {
            InitializeComponent();

            settingBL    = new SettingBL();
            emailSetting = new EmailSetting();

            PopulateData();
        }
Exemplo n.º 2
0
        public EmailSetting GetEmailSetting()
        {
            try
            {
                if (System.IO.File.Exists(EMAIL_SETTING_PATH))
                {
                    XmlDocument _doc = new XmlDocument();
                    _doc.Load(EMAIL_SETTING_PATH);

                    //Get root element
                    XmlElement _root = _doc.DocumentElement;

                    //Get the record at the current index
                    XmlElement _currentEmail = (XmlElement)_root.ChildNodes[0];

                    if (_currentEmail.ChildNodes.Count > 0)
                    {
                        //Show the record information
                        EmailSetting _setting = new EmailSetting();
                        _setting.SenderEmail = _currentEmail.GetElementsByTagName("Email")[0].InnerText;
                        _setting.Password    = EncryptDecrypt.Decrypt(_currentEmail.GetElementsByTagName("Password")[0].InnerText, "123");

                        XmlNodeList _receiver = _root.GetElementsByTagName("Receiver");
                        _setting.ReceiversEmail = new List <string>();

                        foreach (XmlNode r in _receiver)
                        {
                            _setting.ReceiversEmail.Add(r.InnerText);
                        }

                        _setting.Host = _root.GetElementsByTagName("SMTP")[0].InnerText;

                        return(_setting);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtEmail.Text.Trim()) &&
                    !string.IsNullOrEmpty(txtPassword.Text.Trim()) &&
                    !string.IsNullOrEmpty(txtHost.Text.Trim()) &&
                    lstReceivers.ItemCount > 0)
                {
                    emailSetting = new EmailSetting()
                    {
                        SenderEmail = txtEmail.Text.Trim(),
                        Password    = EncryptDecrypt.Encrypt(txtPassword.Text.Trim(), "123"),
                        Host        = txtHost.Text.Trim()
                    };
                    emailSetting.ReceiversEmail = GetReceiversEmail();

                    if (settingBL.Add(emailSetting))
                    {
                        DbUtilityHelper.DisplayMessageBox("Email setting successfully saved", "information");
                    }
                    else
                    {
                        DbUtilityHelper.DisplayMessageBox("Email setting could not be saved. Please try agin!", "error");
                    }
                }
                else
                {
                    DbUtilityHelper.DisplayMessageBox("Required fields cannot be blank.", "warning");
                }
            }
            catch (Exception ex)
            {
                DbUtilityHelper.DisplayMessageBox(ex.Message, "error");
            }
        }
Exemplo n.º 4
0
        private void PopulateData()
        {
            try
            {
                emailSetting = settingBL.GetEmailSetting();
                if (emailSetting != null)
                {
                    txtEmail.Text    = emailSetting.SenderEmail;
                    txtPassword.Text = emailSetting.Password;
                    foreach (var re in emailSetting.ReceiversEmail)
                    {
                        lstReceivers.Items.Add(re);
                    }

                    txtHost.Text = emailSetting.Host;

                    btnRemove.Enabled = lstReceivers.ItemCount > 0 ? true : false;
                }
            }
            catch (Exception ex)
            {
                DbUtilityHelper.DisplayMessageBox(ex.Message, "error");
            }
        }
Exemplo n.º 5
0
        public bool Add(EmailSetting setting)
        {
            try
            {
                XmlDocument _doc = new XmlDocument();

                //Create neccessary nodes
                XmlDeclaration _declaration = _doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
                XmlElement     _root        = _doc.CreateElement("Settings");

                //sender
                XmlElement _sender      = _doc.CreateElement("Sender");
                XmlElement _senderEmail = _doc.CreateElement("Email");
                XmlElement _password    = _doc.CreateElement("Password");

                //SMTP server setting
                XmlElement _smtp = _doc.CreateElement("SMTP");

                //message
                //XmlElement _message = _doc.CreateElement("Receiver");
                //XmlElement _subject = _doc.CreateElement("Email");

                //Add sender's email and password
                _senderEmail.InnerText = setting.SenderEmail;
                _password.InnerText    = setting.Password;

                //Add smtp setting
                _smtp.InnerText = setting.Host;

                //Construct the document
                _doc.AppendChild(_declaration);
                //doc.AppendChild(comment);
                _doc.AppendChild(_root);

                _root.AppendChild(_sender);
                _sender.AppendChild(_senderEmail);
                _sender.AppendChild(_password);

                //Add receivers' email address
                foreach (var email in setting.ReceiversEmail)
                {
                    //Receiver
                    XmlElement _receiver      = _doc.CreateElement("Receiver");
                    XmlElement _receiverEmail = _doc.CreateElement("Email");

                    _root.AppendChild(_receiver);
                    _receiverEmail.InnerText = email;
                    _receiver.AppendChild(_receiverEmail);
                }

                _root.AppendChild(_smtp);

                if (!Directory.Exists(LOCAL_APP_DATA))
                {
                    Directory.CreateDirectory(LOCAL_APP_DATA);
                }

                _doc.Save(EMAIL_SETTING_PATH);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }