好郁闷,做了几天,我的邮件还是发不出去,我的代码如下,请各位大哥,看看~!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Text;
using System.IO;namespace Email1
{ public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button send;
protected System.Web.UI.WebControls.TextBox TextBox3;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.send.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mail=new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = TextBox3.Text;
mail.Body ="body.Text";
//mail.Charset = "GB2312";
StringBuilder sb = new StringBuilder();
sb.Append("你的邮件内容");
mail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "sina.com";
//mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "2");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名(把my_username_here改为你的验证用户名)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wangoicq3344");
//设置验证密码(把password改为你的验证密码)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "168700000");
SmtpMail.Send( mail );
//MessageBox.Show("OK");
//#endregion
/*try
{
mailsmtp.SendMail(mail);
MessageBox.Show("邮件发送成功", "提示",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception )
{ MessageBox.Show("您的邮件发送服务器需要身份验证,或者身份验证失败,\n请修改邮件帐户相关设置");
this.Close();
}*/ }
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Text;
using System.IO;namespace Email1
{ public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button send;
protected System.Web.UI.WebControls.TextBox TextBox3;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.send.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mail=new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = TextBox3.Text;
mail.Body ="body.Text";
//mail.Charset = "GB2312";
StringBuilder sb = new StringBuilder();
sb.Append("你的邮件内容");
mail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "sina.com";
//mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "2");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名(把my_username_here改为你的验证用户名)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wangoicq3344");
//设置验证密码(把password改为你的验证密码)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "168700000");
SmtpMail.Send( mail );
//MessageBox.Show("OK");
//#endregion
/*try
{
mailsmtp.SendMail(mail);
MessageBox.Show("邮件发送成功", "提示",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception )
{ MessageBox.Show("您的邮件发送服务器需要身份验证,或者身份验证失败,\n请修改邮件帐户相关设置");
this.Close();
}*/ }
}
}
“/Email1”应用程序中的服务器错误。
--------------------------------------------------------------------------------与服务器的传输连接失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: 与服务器的传输连接失败。 源错误:
行 85: mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "168700000");
行 86:
行 87: SmtpMail.Send( mail );
行 88: //essageBox.Show("OK");
行 89: //#endregion
源文件: d:\inetpub\wwwroot\email1\webform1.aspx.cs 行: 87
但是我改成SmtpMail.SmtpServer = "Smtp.sina.com";
也没用,还是连不上帐号密码都是正确的
可是用sina 的怎么不可以呢,可以说说吗