www.pudn.com > IntMail.rar > FrmSend.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Net.Mail; 
 
namespace IntMail 
{ 
    public partial class FrmSend : Form 
    { 
        string _getTo = ""; 
        string _getSubject = ""; 
        string _getLr = ""; 
        int _getIsAn = 0;//回复 如果为1此表示转发 
        public FrmSend(string getTo,string getSubject,string getLr,int getIsAn) 
        { 
            InitializeComponent(); 
            _getTo = getTo; 
            _getSubject = getSubject; 
            _getLr = getLr; 
            _getIsAn = getIsAn; 
        } 
 
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        private void FrmSend_Load(object sender, EventArgs e) 
        { 
            textBox2.Text = MailAddress.MailAddressD; 
            textBox2.ReadOnly =true; 
            if (_getIsAn == 0) 
            { 
            //表示回复 
                textBox3.Text = _getTo; 
                textBox5.Text = "Re:" + _getSubject; 
                textBox1.Text = "\r\n\r\n" + _getLr; 
            } 
            //表示转发 
            if (_getIsAn == 1) 
            { 
                textBox5.Text =_getSubject; 
                textBox1.Text = "\r\n\r\n\r\n\r\n" + _getLr; 
            } 
        } 
 
        private void toolStripButton1_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                if (textBox3.Text.Trim() == "") 
                { 
                    MessageBox.Show("收件人不能为空!"); 
                } 
                else 
                { 
                    if (textBox5.Text.Trim() == "") 
                    { 
                        MessageBox.Show("主题不能为空!"); 
                    } 
                    else 
                    { 
                        MailMessage myMail = new MailMessage(); 
                        //设置发件人 
                        myMail.From = new System.Net.Mail.MailAddress(textBox2.Text.Trim(), "豆豆"); 
                        //设置收件人 
                        string[] Ato = textBox3.Text.Trim().Split(';'); 
                        foreach (string temp in Ato) 
                        { 
                            if (temp.Trim() != "") 
                            { 
                                myMail.To.Add(new System.Net.Mail.MailAddress(temp.Trim())); 
                            } 
                        } 
 
                        //设置抄送人 
                        string[] Acc = textBox4.Text.Trim().Split(';'); 
                        foreach (string temp in Acc) 
                        { 
                            if (temp.Trim() != "") 
                            { 
                                myMail.CC.Add(new System.Net.Mail.MailAddress(temp.Trim())); 
                            } 
                        } 
                        //设置邮件正文和主题 
                        myMail.Body = textBox1.Text.Trim(); 
                        myMail.Subject = textBox5.Text.Trim(); 
 
                        //添加附件 
                        if (textBox6.Text.Trim() != "") 
                        { 
                            string[] AFile = textBox6.Text.Trim().Split(','); 
                            foreach (string att in AFile) 
                            { 
                                myMail.Attachments.Add(new Attachment(att)); 
                            } 
                        } 
                        myMail.Priority = MailPriority.High; 
                        myMail.IsBodyHtml = false; 
                        if(comboBox1.Text=="高优先级") 
                        { 
                            myMail.Priority = MailPriority.High; 
                        } 
                        if (comboBox1.Text == "低优先级") 
                        { 
                            myMail.Priority = MailPriority.Low; 
                        } 
                        if (comboBox1.Text == "普通优先级") 
                        { 
                            myMail.Priority = MailPriority.Normal; 
                        } 
                        //设置邮件格式 
                        if (comboBox2.Text == "HTML格式") 
                        { 
                            myMail.IsBodyHtml = true; 
                        } 
                        else 
                        { 
                            myMail.IsBodyHtml = false; 
                        } 
                        SmtpClient smtp1 = new SmtpClient(); 
                        smtp1.Host = MailAddress.MailAddressSMTP; 
                        smtp1.Port = 25; 
                        smtp1.UseDefaultCredentials = true; 
                        smtp1.Credentials = new System.Net.NetworkCredential(MailAddress.MailAddressUser, MailAddress.MailAddressPass); 
                        smtp1.Send(myMail); 
                        MessageBox.Show("系统提示:电子邮件发送成功!"); 
                    } 
                } 
            } 
            catch (Exception ex) 
            { 
                MessageBox.Show(ex.ToString()); 
            } 
        } 
    } 
}