asp.net怎么用代码实现接受邮件修改密码啊 MailMessage类已经过时...
发布网友
发布时间:2024-10-05 17:59
我来回答
共2个回答
热心网友
时间:2024-10-27 19:09
邮件可以用两种方式。第一,用Jmail组件实现。第二种,用using System.Net.Mail;
我给出第二种的代码
先定义类:protected bool Smail(MailAddress messageForm,string name,string pass,string toname,string server,string subject,string body,string ment)
{
MailMessage message = new MailMessage();
Attachment ments;
ments = new Attachment(ment);//附件地址
message.From=messageForm;//发件人
message.To.Add(toname);//收件人
message.Subject = subject;//标题
message.Body = body;//主题
message.Attachments.Add(ments);//附件加入邮件中
message.IsBodyHtml = true;//是否为html格式
message.Priority = MailPriority.High;//邮件发送优先等级
SmtpClient client = new SmtpClient();
client.Host = server;//邮件服务器的地址或ip
client.Port = 25;//邮件服务器地址端口
client.Credentials = new System.Net.NetworkCredential(name, pass);
try
{
client.Send(message);//发送邮件
}
catch (Exception ex)
{
ViewState["error"] = ex;
return false;
}
return true;
}
调用:MailAddress MessageFrom = new MailAddress(name); //发件人邮箱地址
bool bo=Smail(MessageFrom,name, pass, toname, server, subject, body, ment);
if (bo)
Response.Write("<script>alert('邮件发送成功');</script>");
热心网友
时间:2024-10-27 19:08
过时,但还能用啊关键是能用