.net aspx 利用smtp 发送邮件email 简单实用版
分类: c# | 标签: | 日期:2010-04-19
前提是发件邮箱开启了smtp;
using System.Net.Mail;
if (!string.IsNullOrEmpty(Request.Form["email"]) && !string.IsNullOrEmpty(Request.Form["content"]) && !string.IsNullOrEmpty(Request.Form["title"]) && !string.IsNullOrEmpty(Request.Form["name"]))
{
string title = Request.Form["title"].ToString();
string mail = Request.Form["email"].ToString();
string content = Request.Form["content"].ToString();
string name = Request.Form["name"].ToString();
MailMessage message = new MailMessage();
message.From = new MailAddress(“mailsend@bordf.com”, name);
message.To.Add(new MailAddress(mail)); // the email you want to send email to
message.Subject = title;
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = content;
message.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient(“smtp.bordf.com”, 25);
client.Credentials = new System.Net.NetworkCredential(“mailsend@bordf.com”, “password”); //
client.EnableSsl = false; //经过ssl加密
object userState = message;
try
{
client.Send(message);
Response.Write(“邮件成功发送到” + message.To.ToString());
}
catch (Exception exp)
{
Response.Write(“邮件发送失败”);
}
