using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net.Mail;

namespace Ex09_9
{
    public partial class Form1 : Form
    {

        MailMessage Mail;
        SmtpClient Client;

        public Form1()
        {
            InitializeComponent();
        }

        public void CreateTimeoutTestMessage(string server)
        {
            try
            {
                //实例MailMessage类
                Mail = new MailMessage(textBox1 .Text,textBox2 .Text );
                Mail.Subject = textBox3.Text.Trim().ToString();
                Mail.Body = textBox4.Text.Trim().ToString();
                Client = new SmtpClient(server, 25);//实例一个SmtpClient类
                Client.Send(Mail);
                MessageBox.Show("邮件发送成功！！！");
            }
            catch (Exception ey)
            {
                MessageBox.Show(ey.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox4.Text.Trim().ToString() != "")
            {
                CreateTimeoutTestMessage("pop.163.com");//参数传的是POP３服务器的名称
            }
            else
            {
                MessageBox.Show("请认真填写邮件！");
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}
