您的位置:首页 > 编程语言 > ASP

ASP.NET 发邮件

2011-12-20 23:20 148 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Net.Mail;

using System.Net;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

MailMessage msg = new MailMessage();

msg.Body = this.TextBox2.Text;

msg.From = new MailAddress("993887459@qq.com");

msg.Subject = this.TextBox1.Text;

msg.To.Add("993887459@qq.com");

//SmtpClient sc = new SmtpClient("smtp.126.com", 25);

//SmtpClient sc1 = new SmtpClient("smtp.qq.com",25);

//sc1.Credentials = new NetworkCredential("993887459","asdf");

//sc1.Send(msg);

msg.IsBodyHtml = true; //邮件默认格式是纯文本 //可发送超链接 如:<a href="http://www.baidu.com">百度</a>

SmtpClient sc2 = new SmtpClient();

sc2.Host = "smtp.qq.com";

sc2.Port = 25;

NetworkCredential nc = new NetworkCredential();

nc.UserName = "youxiangming";

nc.Password = "mima";

sc2.Credentials = nc;

string filename = this.FileUpload1.FileName;

this.FileUpload1.SaveAs(Server.MapPath("~/") + filename);

Attachment att = new Attachment(Server.MapPath("~/") + filename);

msg.Attachments.Add(att);

sc2.Send(msg);

}

protected void Button2_Click(object sender, EventArgs e)

{

jmail.Message msg = new jmail.MessageClass();

msg.Subject = this.TextBox1.Text;

msg.Body = this.TextBox2.Text;

msg.From = "993887459@qq.com";

msg.AddRecipient("993887459@qq.com");

msg.MailServerUserName = "youxiangming";

msg.MailServerPassWord = "mima";

msg.Charset = "utf-8"; //显示汉字

msg.ContentType = "text/html";

msg.Send("smtp.qq.com");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: