Пример #1
0
        /*添加收件人*/
        private void button3_Click(object sender, EventArgs e)
        {
            // 打开选择路径
            //FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            //  FileStream fs = new FileStream(Application.StartupPath + "\\address.txt", FileMode.Open, FileAccess.Read);

            string oneEmail;

            if (File.Exists(Application.StartupPath + "\\address.txt"))
            {
                #region  导入默认位置的邮件地址
                StreamReader sr = new StreamReader(Application.StartupPath + "\\address.txt");
                //  文件存在则导入
                Regex myreg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); //email验证
                while (sr.Peek() != -1)
                {
                    oneEmail = sr.ReadLine();
                    if (myreg.IsMatch(oneEmail))
                    {
                        t_to.Items.Add(oneEmail);
                    }
                }
                #endregion
            }
            else
            {
                #region   单个地址添加
                add ad = new add();
                if (ad.ShowDialog() == DialogResult.OK && !t_to.Items.Contains(ad.email))
                {
                    t_to.Items.Add(ad.email);
                }
                //DataTable dt = new DataTable("email");
                //dt.Columns.Add("address");
                //dt.Rows.Add(ad.email);



                //dt.WriteXml(Application.StartupPath + "\\address.xml",XmlWriteMode.);
                //XmlDocument doc = new XmlDocument();
                //doc.Load("a.xml ");
                //doc.DocumentElement.AppendChild(doc.ImportNode(doc.DocumentElement.FirstChild, true));
                //XmlTextWriter xw = new XmlTextWriter(new StreamWriter("a.xml "));
                //xw.Formatting = Formatting.Indented;
                //doc.WriteTo(xw);
                //xw.Close();
                #endregion
            }
        }
Пример #2
0
        /*添加收件人*/
        private void button3_Click(object sender, EventArgs e)
        {
            // 打开选择路径
            //FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            //  FileStream fs = new FileStream(Application.StartupPath + "\\address.txt", FileMode.Open, FileAccess.Read);

            string oneEmail;
            if (File.Exists(Application.StartupPath + "\\address.txt"))
            {
                #region  导入默认位置的邮件地址
                StreamReader sr = new StreamReader(Application.StartupPath + "\\address.txt");
                //  文件存在则导入
                Regex myreg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); //email验证
                while (sr.Peek() != -1)
                {
                    oneEmail = sr.ReadLine();
                    if (myreg.IsMatch(oneEmail))
                        t_to.Items.Add(oneEmail);
                }
                #endregion
            }
            else
            {
                #region   单个地址添加
                add ad = new add();
                if (ad.ShowDialog() == DialogResult.OK && !t_to.Items.Contains(ad.email))
                    t_to.Items.Add(ad.email);
                //DataTable dt = new DataTable("email");
                //dt.Columns.Add("address");
                //dt.Rows.Add(ad.email);

                //dt.WriteXml(Application.StartupPath + "\\address.xml",XmlWriteMode.);
                //XmlDocument doc = new XmlDocument();
                //doc.Load("a.xml ");
                //doc.DocumentElement.AppendChild(doc.ImportNode(doc.DocumentElement.FirstChild, true));
                //XmlTextWriter xw = new XmlTextWriter(new StreamWriter("a.xml "));
                //xw.Formatting = Formatting.Indented;
                //doc.WriteTo(xw);
                //xw.Close();
                #endregion
            }
        }