C#发送邮件(VS2008)
2010-10-14 16:36
246 查看
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;
namespace WebUI
{
public partial class SendMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
MailMessage mm = new MailMessage();
MailAddress Fromma = new MailAddress("490261180@qq.com");
MailAddress Toma = new MailAddress("122097184@qq.com", null);
mm.From= Fromma;
//收件人
mm.To.Add("122097184@qq.com");
//邮箱标题
mm.Subject = "Hello";
//邮件内容
mm.Body = "大家好!";
//内容的编码格式
mm.BodyEncoding = System.Text.Encoding.UTF8;
//mm.ReplyTo = Toma;
//mm.Sender =Fromma;
//mm.IsBodyHtml = false;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
mm.CC.Add(Toma);
SmtpClient sc = new SmtpClient();
NetworkCredential nc=new NetworkCredential();
nc.UserName = "490261180@qq.com";//你的邮箱地址
nc.Password = "123456";//你的邮箱密码
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
//如果这里报mail from address must be same as authorization user这个错误,是你的QQ邮箱没有开启SMTP,
//到你自己的邮箱设置一下就可以啦!在帐户下面,如果是163邮箱的话,下面该成smtp.163.com
sc.Host = "smtp.qq.com";
sc.Send(mm);
}
catch( Exception ex )
{
throw new Exception(ex.Message);
}
}
}
}
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;
namespace WebUI
{
public partial class SendMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
MailMessage mm = new MailMessage();
MailAddress Fromma = new MailAddress("490261180@qq.com");
MailAddress Toma = new MailAddress("122097184@qq.com", null);
mm.From= Fromma;
//收件人
mm.To.Add("122097184@qq.com");
//邮箱标题
mm.Subject = "Hello";
//邮件内容
mm.Body = "大家好!";
//内容的编码格式
mm.BodyEncoding = System.Text.Encoding.UTF8;
//mm.ReplyTo = Toma;
//mm.Sender =Fromma;
//mm.IsBodyHtml = false;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
mm.CC.Add(Toma);
SmtpClient sc = new SmtpClient();
NetworkCredential nc=new NetworkCredential();
nc.UserName = "490261180@qq.com";//你的邮箱地址
nc.Password = "123456";//你的邮箱密码
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
//如果这里报mail from address must be same as authorization user这个错误,是你的QQ邮箱没有开启SMTP,
//到你自己的邮箱设置一下就可以啦!在帐户下面,如果是163邮箱的话,下面该成smtp.163.com
sc.Host = "smtp.qq.com";
sc.Send(mm);
}
catch( Exception ex )
{
throw new Exception(ex.Message);
}
}
}
}
相关文章推荐
- C# 邮件发送接收
- C#发送邮件异常,返回信息乱码
- C# 简易邮件客户端,自动发送邮件
- c# 发送邮件(简单一点比较好)
- C#发送邮件
- c# 发送邮件
- 使用C#和Java发送邮件(转载)
- C#使用CDO发送邮件
- C#发送邮件类库
- C#的简单的邮件发送和接收
- C# 用 SMPT 发送邮件
- 这段发c#邮件的代码怎么在自己机器上调试时怎么经常发送不了邮件啊
- C# WebService (三)SMTP邮件发送功能
- C# 邮件发送方法【webMail方式】
- C#编写发送邮件组件
- C# 通过Exchange server 发送邮件
- c# 邮件发送
- C#邮件发送问题(一)
- C#中邮件发送的函数(使用SMTP)
- C#发送邮件