我不知道各位对这个namespace有什么疑问没?
我感觉 还没1。1版本的实在,就从发EMAIL来说。
下面是2。0版的:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Web.Mail;
using System.Net.Mail;
using System.Net;
using System.Text;
/// <summary>
/// 163email test fail
/// the reason:not found
/// </summary>public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// System.Net.Mail.SmtpClient aa=new System.Net.Mail.SmtpClient(
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//Response.Write(Sended("jianbingzuo","[email protected]","好个",true,":saa猪样的","smtp.163.com","jianbingzuo","fang530"));
SendMail("smtp.163.com", "jianbingzuo", "fang530", "[email protected]", "[email protected]", "测试2.0自动发送邮件", "test content", "");
Response.Write("OK");
}
catch(Exception ee)
{
Response.Write("fail"+ee.Message.ToString());
}
} /// <summary>
/// 发送邮件
/// </summary>
/// <param name= "strSmtpServer "> smtp地址 </param>
/// <param name= "UserName "> 用户名 </param>
/// <param name= "Password "> 密码 </param>
/// <param name= "strFrom "> 发信人地址 </param>
/// <param name= "strto "> 收信人地址 </param>
/// <param name= "strSubject "> 邮件标题 </param>
/// <param name= "strBody "> 邮件正文 </param>
public static void SendMail(string strSmtpServer,string UserName,string Password,string strFrom,string strto,string strSubject,string strBody,string strFileName)
{
//生成一个 使用SMTP发送邮件的客户端对象
System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient(strSmtpServer); //表示以当前登录用户的默认凭据进行身份验证
client.UseDefaultCredentials=true;
//包含用户名和密码
client.Credentials=new System.Net.NetworkCredential(UserName,Password); //指定如何发送电子邮件。
//Network 电子邮件通过网络发送到 SMTP 服务器。
//PickupDirectoryFromIis 将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。
//SpecifiedPickupDirectory 将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。 client.DeliveryMethod=System.Net.Mail.SmtpDeliveryMethod.Network; //建立邮件对象
System.Net.Mail.MailMessage message=new System.Net.Mail.MailMessage(strFrom,strto,strSubject,strBody);
//定义邮件正文,主题的编码方式
message.BodyEncoding=System.Text.Encoding.GetEncoding("gb2312");
message.SubjectEncoding =System.Text.Encoding.GetEncoding("gb2312");
//获取或设置一个值,该值指示电子邮件正文是否为 HTML。
message.IsBodyHtml=false;
//指定邮件优先级
message.Priority=System.Net.Mail.MailPriority.Normal;
//添加附件
//System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(@ "f:/baihe.txt ");
if(strFileName!=""&&strFileName!=null)
{
Attachment data=new Attachment(strFileName);
message.Attachments.Add(data);
}
//发件人身份验证,否则163 发不了
client.Credentials=new System.Net.NetworkCredential(strFrom,Password);
//发送
client.Send(message);
}
下面是1。1版的 1。1版能发出邮件。2,0版不知道为什么发不出去。疑惑中。希望高手指教。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Text;public partial class Sendemail_demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<title>自动发个EMAIL那有这么的毛病-日!</title>"); }
/// <summary>
/// 1。1版本的
/// </summary>
/// <param name="mailhead"></param>
/// <param name="mailbody"></param>
/// <param name="emailadd"></param>
/// <returns></returns>
public static bool SendMail(string mailhead, string mailbody, string emailadd)
{
if (emailadd != "")
{
//创建MailMessage对象
System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
//设置收件人的邮件地址
mailMsg.To = emailadd;
//设置发送者的邮件地址
mailMsg.From = "[email protected]";
//设置邮件主题
mailMsg.Subject = mailhead;
//设置邮件内容
mailMsg.BodyFormat = System.Web.Mail.MailFormat.Html;
if (mailbody != "")
{
mailMsg.Body = mailbody; //设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "jianbingzuo");
//设置用户密码
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "fang530");
try
{
//设置发送邮件服务器 202.108.5.142
System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com";
//发送邮件
System.Web.Mail.SmtpMail.Send(mailMsg);
return true;
}
catch
{
return false;
}
}
else
return false;
}
else
return false;
}
protected void Button1_Click(object sender, EventArgs e)
{
bool ok= SendMail("收到了吧", "呵呵", "[email protected]");
if (ok=true)
{
Response.Write("ok");
}
else
{
Response.Write("fail");
}
}
}
我感觉 还没1。1版本的实在,就从发EMAIL来说。
下面是2。0版的:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Web.Mail;
using System.Net.Mail;
using System.Net;
using System.Text;
/// <summary>
/// 163email test fail
/// the reason:not found
/// </summary>public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// System.Net.Mail.SmtpClient aa=new System.Net.Mail.SmtpClient(
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//Response.Write(Sended("jianbingzuo","[email protected]","好个",true,":saa猪样的","smtp.163.com","jianbingzuo","fang530"));
SendMail("smtp.163.com", "jianbingzuo", "fang530", "[email protected]", "[email protected]", "测试2.0自动发送邮件", "test content", "");
Response.Write("OK");
}
catch(Exception ee)
{
Response.Write("fail"+ee.Message.ToString());
}
} /// <summary>
/// 发送邮件
/// </summary>
/// <param name= "strSmtpServer "> smtp地址 </param>
/// <param name= "UserName "> 用户名 </param>
/// <param name= "Password "> 密码 </param>
/// <param name= "strFrom "> 发信人地址 </param>
/// <param name= "strto "> 收信人地址 </param>
/// <param name= "strSubject "> 邮件标题 </param>
/// <param name= "strBody "> 邮件正文 </param>
public static void SendMail(string strSmtpServer,string UserName,string Password,string strFrom,string strto,string strSubject,string strBody,string strFileName)
{
//生成一个 使用SMTP发送邮件的客户端对象
System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient(strSmtpServer); //表示以当前登录用户的默认凭据进行身份验证
client.UseDefaultCredentials=true;
//包含用户名和密码
client.Credentials=new System.Net.NetworkCredential(UserName,Password); //指定如何发送电子邮件。
//Network 电子邮件通过网络发送到 SMTP 服务器。
//PickupDirectoryFromIis 将电子邮件复制到挑选目录,然后通过本地 Internet 信息服务 (IIS) 传送。
//SpecifiedPickupDirectory 将电子邮件复制到 SmtpClient.PickupDirectoryLocation 属性指定的目录,然后由外部应用程序传送。 client.DeliveryMethod=System.Net.Mail.SmtpDeliveryMethod.Network; //建立邮件对象
System.Net.Mail.MailMessage message=new System.Net.Mail.MailMessage(strFrom,strto,strSubject,strBody);
//定义邮件正文,主题的编码方式
message.BodyEncoding=System.Text.Encoding.GetEncoding("gb2312");
message.SubjectEncoding =System.Text.Encoding.GetEncoding("gb2312");
//获取或设置一个值,该值指示电子邮件正文是否为 HTML。
message.IsBodyHtml=false;
//指定邮件优先级
message.Priority=System.Net.Mail.MailPriority.Normal;
//添加附件
//System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(@ "f:/baihe.txt ");
if(strFileName!=""&&strFileName!=null)
{
Attachment data=new Attachment(strFileName);
message.Attachments.Add(data);
}
//发件人身份验证,否则163 发不了
client.Credentials=new System.Net.NetworkCredential(strFrom,Password);
//发送
client.Send(message);
}
下面是1。1版的 1。1版能发出邮件。2,0版不知道为什么发不出去。疑惑中。希望高手指教。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Text;public partial class Sendemail_demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<title>自动发个EMAIL那有这么的毛病-日!</title>"); }
/// <summary>
/// 1。1版本的
/// </summary>
/// <param name="mailhead"></param>
/// <param name="mailbody"></param>
/// <param name="emailadd"></param>
/// <returns></returns>
public static bool SendMail(string mailhead, string mailbody, string emailadd)
{
if (emailadd != "")
{
//创建MailMessage对象
System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
//设置收件人的邮件地址
mailMsg.To = emailadd;
//设置发送者的邮件地址
mailMsg.From = "[email protected]";
//设置邮件主题
mailMsg.Subject = mailhead;
//设置邮件内容
mailMsg.BodyFormat = System.Web.Mail.MailFormat.Html;
if (mailbody != "")
{
mailMsg.Body = mailbody; //设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "jianbingzuo");
//设置用户密码
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "fang530");
try
{
//设置发送邮件服务器 202.108.5.142
System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com";
//发送邮件
System.Web.Mail.SmtpMail.Send(mailMsg);
return true;
}
catch
{
return false;
}
}
else
return false;
}
else
return false;
}
protected void Button1_Click(object sender, EventArgs e)
{
bool ok= SendMail("收到了吧", "呵呵", "[email protected]");
if (ok=true)
{
Response.Write("ok");
}
else
{
Response.Write("fail");
}
}
}
client.Credentials=new System.Net.NetworkCredential(UserName,Password); //发件人身份验证,否则163 发不了
client.Credentials=new System.Net.NetworkCredential(strFrom,Password); -------------------------------------
你自己查一下自己的代码吧。
.Net只有越做越好,不会是越做越差的。
无语了。呵呵。