好郁闷,做了几天,我的邮件还是发不出去,我的代码如下,请各位大哥,看看~!
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();
}*/ }
}
}

解决方案 »

  1.   

    运行时,提示这样的错误:
    “/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 
      

  2.   

    首先,你的SmtpMail.SmtpServer = "sina.com";这里SMTP地址对不对,请核实。我用过smtp.163.com是可以的。如果楼主有163的邮箱可以试试。其次,你这个邮箱的用户名密码都写对了没?mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wangoicq3344");  mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "168700000");
      

  3.   

    是的, 我改错了SmtpMail.SmtpServer = "sina.com";
    但是我改成SmtpMail.SmtpServer = "Smtp.sina.com";
    也没用,还是连不上帐号密码都是正确的
      

  4.   

    好了,我改成Smtp.163.com 后可以了
    可是用sina 的怎么不可以呢,可以说说吗
      

  5.   

    呵呵,,知道了,我今天刚刚啊查到了谢谢你哦bobo