protected void Unnamed1_Click(object sender, EventArgs e)
{
MessageClass myJmail = new MessageClass();
myJmail.Charset = "GB2312";
myJmail.Silent = true;
myJmail.From = "[email protected]";
myJmail.FromName = "kuo";
myJmail.AddRecipient("[email protected]");
myJmail.ContentType = "text/html";
myJmail.MailServerUserName = "583479434";
myJmail.MailServerPassWord = "**********";
myJmail.ReplyTo = "[email protected]";
myJmail.Subject = "程序发送邮件";
myJmail.Body = "就这样";
if (myJmail.Send("smtp.qq.com", false))
{
Response.Write("邮件发送成功");
}
else
{
Response.Write("邮件发送失败");
}
}
myJmail.FromName = "kuo"; //设置发送方名字
myJmail.AddRecipient("[email protected]"); //接收方邮箱,群发的发可以继续添加
myJmail.ContentType = "text/html"; //设置页面格式,text/html为网页格式
myJmail.MailServerUserName = "583479434"; //发送方邮箱的登录名
myJmail.MailServerPassWord = "**********"; //发送方邮箱密码 myJmail.ReplyTo = "[email protected]"; //这句期待大家解释, myJmail.Subject = "程序发送邮件"; //邮件主题
myJmail.Body = "就这样"; //邮件内容,当然可以更复杂,可做一个网页放上去if (myJmail.Send("smtp.qq.com", false)) //smtp.qq.com根据发送方的邮箱设置,smtp服务, 当然如果你服务器上有配置smtp的话可以用自己的,这边是用到qq邮箱的smtp,至于后面的参数,期待解释
{
Response.Write("邮件发送成功");
}
找了一些资料,可以解释上面的两句
myJmail.Silent = true; 设置为true时,就是忽略发送错误
myJmail.ReplyTo = "[email protected]"; 设置接收回复的邮箱地址太好了,一件心事可以放下了. . . . .
//邮件发送
private void sendEmail1()
{
MailMessage MyMail = new MailMessage();
MyMail.From = new MailAddress("[email protected]", "小明");//邮件发送者地址,昵称
MyMail.To.Add(new MailAddress("[email protected]"));//收件人地址
MyMail.Subject = "标题";//邮件主题
MyMail.Body = "正文内容 " ;//邮件内容
MyMail.IsBodyHtml = false;//设定邮件内容是不是html文本
SmtpClient smtpclient = new SmtpClient();//简单邮件传送协议对象
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; // 电子邮件通过网络发送
smtpclient.Host = "smtp.126.com";//设置通信服务器,发件人SMTP协议 这个很重要
smtpclient.Credentials = new System.Net.NetworkCredential("[email protected]", "密码");
smtpclient.Send(MyMail);
}