Exemple #1
0
        public string GetAllJSON()
        {
            string result = "";

            var listMailServer = new List <MailServer>();

            if (User.Current != null)
            {
                var security = new Security(User.Current.Password);
                var mails    = security.ReadMailConfiguration(User.Current.Path);

                foreach (XmlNode node in mails.SelectNodes("root/mails/mail"))
                {
                    var mail = new MailServer
                    {
                        Name     = node.SelectSingleNode("name").InnerText,
                        Server   = node.SelectSingleNode("server").InnerText,
                        Port     = int.Parse(node.SelectSingleNode("port").InnerText),
                        Username = node.SelectSingleNode("user").InnerText,
                        Password = node.SelectSingleNode("password").InnerText
                    };
                    listMailServer.Add(mail);
                }

                result = new JavaScriptSerializer().Serialize(listMailServer);
            }

            return(result);
        }
Exemple #2
0
        public MailServer GetBy(string name)
        {
            MailServer mailServer = null;

            if (User.Current != null)
            {
                var security = new Security(User.Current.Password);
                var mails    = security.ReadMailConfiguration(User.Current.Path);

                XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']");
                if (node != null)
                {
                    mailServer          = new MailServer();
                    mailServer.Name     = node.SelectSingleNode("name").InnerText;
                    mailServer.Server   = node.SelectSingleNode("server").InnerText;
                    mailServer.Username = node.SelectSingleNode("user").InnerText;
                    mailServer.Password = node.SelectSingleNode("password").InnerText;

                    int.TryParse(node.SelectSingleNode("port").InnerText, out int port);

                    mailServer.Port = port;
                }
            }

            return(mailServer);
        }
Exemple #3
0
        public string GetByJSON(string name)
        {
            string result = "";

            MailServer mailServer = null;

            if (User.Current != null)
            {
                var         security = new Security(User.Current.Password);
                XmlDocument mails    = security.ReadMailConfiguration(User.Current.Path);

                XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']");
                if (node != null)
                {
                    mailServer = new MailServer
                    {
                        Name     = node.SelectSingleNode("name").InnerText,
                        Server   = node.SelectSingleNode("server").InnerText,
                        Username = node.SelectSingleNode("user").InnerText,
                        Password = node.SelectSingleNode("password").InnerText
                    };

                    int.TryParse(node.SelectSingleNode("port").InnerText, out int port);

                    mailServer.Port = port;

                    result = new JavaScriptSerializer().Serialize(mailServer);
                }
            }

            return(result);
        }
        public void UpdateMail(string name)
        {
            MailServer mailServer = new MailServer();
            var current = mailServer.GetBy(name);

            if (current != null)
            {
                int Num;
                bool isNum = int.TryParse(tbxPort.Text, out Num);

                if (isNum)
                {
                    current.Name = tbxName.Text;
                    current.Server = tbxServer.Text;
                    current.Username = tbxUsername.Text;
                    current.Password = tbxPassword.Text;
                    current.Port = Num;

                    int result = current.Update();
                    if (result == 1)
                    {
                        frmManager manager = (frmManager)Application.OpenForms["frmManager"];
                        manager.SelectTab("tabMails");
                        this.Close();
                    }
                }
            }
        }
 public void DeleteMail(string name)
 {
     MailServer mail = new MailServer();
     mail.Name = name;
     bool result = mail.Delete();
     if (result)
     {
         LoadMail();
     }
 }
        public frmMailUpdate(string name)
        {
            InitializeComponent();

            if (User.Current != null)
            {
                IsAddNew = false;
                LoadLanguage(IsAddNew);
                _name = name;

                MailServer mailserver = new MailServer();
                var current = mailserver.GetBy(name);

                if (current != null)
                {
                    tbxName.Text = current.Name;
                    tbxServer.Text = current.Server;
                    tbxUsername.Text = current.Username;
                    tbxPassword.Text = current.Password;
                    tbxPort.Text = current.Port.ToString();
                }
            }
        }
Exemple #7
0
        public string sendEmail(string username, string password, string server, string port, string email, string subject, string content)
        {
            string result = "False";

            MailServer mailserver = new MailServer();
            mailserver.Username = username;
            mailserver.Password = password;
            mailserver.Server = server;
            mailserver.Port = int.Parse(port);

            result = mailserver.SendEmail(email, subject, content).ToString();

            return result;
        }
        public string GetByJSON(string name)
        {
            string result = "";

            MailServer mailServer = new MailServer();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument mails = security.ReadMailConfiguration(User.Current.Path);

                XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']");
                if (node != null)
                {
                    mailServer.Name = node.SelectSingleNode("name").InnerText;
                    mailServer.Server = node.SelectSingleNode("server").InnerText;
                    mailServer.Username = node.SelectSingleNode("user").InnerText;
                    mailServer.Password = node.SelectSingleNode("password").InnerText;

                    int port = 0;

                    int.TryParse(node.SelectSingleNode("port").InnerText, out port);

                    mailServer.Port = port;

                    result = new JavaScriptSerializer().Serialize(mailServer);
                }
            }

            return result;
        }
        public MailServer GetBy(string name)
        {
            MailServer mailServer = new MailServer();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument mails = security.ReadMailConfiguration(User.Current.Path);

                XmlNode node = mails.SelectSingleNode("/root/mails/mail[name='" + name + "']");
                if (node != null)
                {
                    mailServer.Name = node.SelectSingleNode("name").InnerText;
                    mailServer.Server = node.SelectSingleNode("server").InnerText;
                    mailServer.Username = node.SelectSingleNode("user").InnerText;
                    mailServer.Password = node.SelectSingleNode("password").InnerText;

                    int port = 0;

                    int.TryParse(node.SelectSingleNode("port").InnerText, out port);

                    mailServer.Port = port;
                }
                else
                {
                    mailServer = null;
                }
            }
            else
            {
                mailServer = null;
            }

            return mailServer;
        }
        public string GetAllJSON()
        {
            string result = "";

            List<MailServer> listMailServer = new List<MailServer>();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument mails = security.ReadMailConfiguration(User.Current.Path);

                foreach (XmlNode node in mails.SelectNodes("root/mails/mail"))
                {
                    MailServer mail = new MailServer();
                    mail.Name = node.SelectSingleNode("name").InnerText;
                    mail.Server = node.SelectSingleNode("server").InnerText;
                    mail.Port = int.Parse(node.SelectSingleNode("port").InnerText);
                    mail.Username = node.SelectSingleNode("user").InnerText;
                    mail.Password = node.SelectSingleNode("password").InnerText;
                    listMailServer.Add(mail);
                }

                result = new JavaScriptSerializer().Serialize(listMailServer);
            }

            return result;
        }
        public List<MailServer> GetAll()
        {
            List<MailServer> listMailServer = new List<MailServer>();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument mails = security.ReadMailConfiguration(User.Current.Path);

                foreach (XmlNode node in mails.SelectNodes("root/mails/mail"))
                {
                    MailServer mail = new MailServer();
                    mail.Name = node.SelectSingleNode("name").InnerText;
                    mail.Server = node.SelectSingleNode("server").InnerText;
                    mail.Port = int.Parse(node.SelectSingleNode("port").InnerText);
                    mail.Username = node.SelectSingleNode("user").InnerText;
                    mail.Password = node.SelectSingleNode("password").InnerText;
                    listMailServer.Add(mail);
                }
            }

            return listMailServer;
        }
        private void LoadMail()
        {
            MailServer mailserver = new MailServer();
            List<MailServer> lstMail = mailserver.GetAll();

            Security security = new Security();

            lvMails.Items.Clear();

            foreach(MailServer m in lstMail)
            {
                ListViewItem item = new ListViewItem(new[] { m.Name, m.Server, m.Username, security.encrypt(User.Current.PublicKey, m.Password), m.Port.ToString() });
                lvMails.Items.Add(item);
            }
        }
Exemple #13
0
        private void AddNew()
        {
            MailServer mailServer = new MailServer();
            string message = Language.Resource.Message;
            Security security = new Security();
            

            bool check = mailServer.CheckExists(tbxName.Text);

            if (check)
            {
                MessageBox.Show(Language.Resource.NameExists, message);
            }
            else
            {
                int Num;
                bool isNum = int.TryParse(tbxPort.Text, out Num);

                if (isNum)
                {
                    mailServer.Name = tbxName.Text;
                    mailServer.Server = tbxServer.Text;
                    mailServer.Username = tbxUsername.Text;
                    mailServer.Password = tbxPassword.Text;
                    mailServer.Port = Num;

                    int result = mailServer.Add();
                    if (result == 1)
                    {
                        frmManager manager = (frmManager)Application.OpenForms["frmManager"];
                        manager.SelectTab("tabMails");
                        this.Close();
                    }
                }
                else
                {
                    tbxPort.Focus();
                    MessageBox.Show(Language.Resource.NotNumber, message);
                }
            }
        }
Exemple #14
0
        public string sendEmail(string name, string email, string subject, string content)
        {
            string result = "False";

            if (User.Current != null && !string.IsNullOrEmpty(name))
            {
                MailServer mailserver = new MailServer();
                var item = mailserver.GetBy(name);
                if (item != null)
                {
                    mailserver.Username = item.Username;
                    mailserver.Password = item.Password;
                    mailserver.Server = item.Server;
                    mailserver.Port = item.Port;

                    result = mailserver.SendEmail(email, subject, content).ToString();
                }
            }
            return result;
        }