当前位置:Gxlcms > asp.net > .net发送邮件实现代码

.net发送邮件实现代码

时间:2021-07-01 10:21:17 帮助过:18人阅读

MailMessage objMail = new MailMessage();
objMail.Subject = "邮件主题";
objMail.Body = "邮件正文";
string mfrom = txtFrom.Value; //从页面读取发送者地址
objMail.From = new MailAddress(mfrom);
string mt = txtTo.Value; //从页面读取接收者地址
MailAddress ma = new MailAddress(mt);
objMail.To.Add(ma);
objMail.IsBodyHtml = true;//指示邮件为html格式的值
objMail.Priority = MailPriority.High;//设置邮件的优先级
objMail.Attachments.Add(new Attachment("F:\\aba.doc"));//添加附件
SmtpClient smtp = new SmtpClient();
smtp.Host = "……"//smtp事务的IP地址,如smtp.cc.com
smtp.Send(objMail);//发送邮件

人气教程排行