MailMessage mail = new MailMessage();
mail.To.Add("**@**.com");
mail.Subject = "test";
mail.Body = "nihao";
bool b = false;
//smtp服务器
string smtp = "smtp.163.com";
//发件人邮箱用户名
string user = "bao";
//密码
string pwd = "*******";
//发件人邮箱
string sendMail = "bao@163.com";
SmtpClient client = new SmtpClient();
client.Host = smtp;
client.UseDefaultCredentials = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential(user, pwd);
mail.From = new MailAddress(sendMail);
string errmsg="";
try
{
client.Send(mail);
b = true;
}
catch (Exception ex)
{
errmsg = ex.Message;
}
if (b)
{
this.Label1.Text = "发送成功!";
}
else
{
this.Label1.Text = errmsg;
}