using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Web.Mail;
namespace HrSalary
{
    public partial class EmailSender : Form
    {
        public EmailSender()
        {
            InitializeComponent();
        }
        private string sender_check()
        {
            string error = "";
            if (this.textBox4.Text =="" || this.textBox4.Text.Trim().Equals(""))
            {
                error = "发件人邮件不能为空!\n    请重新更新\n";
                return error;
            }
            if ((this.textBox4.Text.IndexOf("@") == -1) ||( this.textBox4.Text.IndexOf(".") == -1))
            {
                error += "发件人油箱格式不正确!\n    请重新更新\n";
                return error;
            }
            return error;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string error = "";
            error = sender_check();
            if (error != "")
            {
                MessageBox.Show(error);
                return;
            }
            else
            {
                MailMessage mailObj = new MailMessage();
                mailObj.From = this.textBox4.Text; //谁发的
                mailObj.To = this.textBox1.Text;          //发给谁
                mailObj.Subject = this.textBox2.Text;//邮件主题
                mailObj.Body = this.richTextBox1.Text;      //邮件内容
                mailObj.BodyFormat = MailFormat.Html;//邮件形式 
                mailObj.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");//gb18030
                mailObj.Priority = MailPriority.High;
                //以下完成验证
                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/senda_username", this.textBox6.Text); //set your a_username here
                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.textBox5.Text); //set your password here
                SmtpMail.SmtpServer = this.textBox3.Text;
                SmtpMail.Send(mailObj);
                
                MessageBox.Show("发送成功!~");
            }
         
}
        private void button3_Click(object sender, EventArgs e)
        {
            
        }
    }
}
邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available
这是什么错误?



 
											





 
	    

 
	