using System.Web.Mail;public void sendMail()
{
MailMessage mail1 = new MailMessage();
mail1.Body="body here";
mail1.From="[email protected]";
mail1.To="[email protected]";
mail1.Subject="aaaa"; 
mail1.Priority=MailPriority.High; 
mail1.BodyFormat=MailFormat.Text ; mail1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
mail1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","sendusername");
mail1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","sendpassword"); SmtpMail.SmtpServer="mail.tq668.com";
SmtpMail.Send(mail1);
}
这是我的一些参数和方法 配置是绝对没有问题的已经测试过了,但是就是不能成功发送,请问还需要在什么地方配置一下吗?在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!在线等~!~!~!
配置的sendusername和sendpassword因为不方便所以不透露给大家了,高手来啊~!
忘了还有错误信息The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available 源错误: 
行 67: 
行 68:  SmtpMail.SmtpServer="mail.tq668.com";
行 69:  SmtpMail.Send(mail1);
行 70:  }
行 71:  }

解决方案 »

  1.   

    你用JMAIL试试吧,不要在一颗树上吊死呵呵
    1.安装jmail4.3 2.找到jmail.dll(Program Files\Dimac\w3JMail4下)3.执行Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\ildasm.exe(可使用Visual Studio .Net 2003 命令提示),格式如下:tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:myJmail.dll /namespace:myJmail就是我在Visual Studio .Net 2005命令提示下编译执行 tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:myJmail.dll /namespace:myJmail我的代码如下:
    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.Web.Util;
    using myJmail;using Tool;
    using Manager;
    using Entity;public partial class UserControls_Jmaill : System.Web.UI.UserControl
    {
        string strCurrentPath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                this.lblTitle.Text = "发送邮件控件";
                myJmail.Message Jmail = new myJmail.Message();
                DateTime t = DateTime.Now;
                String Subject = this.txtTitle.Text;
                String body = this.txtContent.Text;
                String FromEmail = this.txtFormEmail.Text;//你的email
                String ToEmail = this.txtToEmail.Text;//对方的email
                String AddAttachment = this.FileUploadSubject.PostedFile.FileName;
                //Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
                Jmail.Silent = true;
                //Jmail创建的日志,前提loging属性设置为true
                Jmail.Logging = true;
                //字符集,缺省为"US-ASCII"
                Jmail.Charset = "GB2312";
                //信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
                Jmail.ContentType = "text/html";
                //添加收件人
                Jmail.AddRecipient(ToEmail, "", "");
                Jmail.From = FromEmail;
                //发件人邮件用户名
                Jmail.MailServerUserName = FromEmail;
                //发件人邮件密码
                Jmail.MailServerPassWord = "kongwei";
                //设置邮件标题
                Jmail.Subject = Subject;
                //邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
                Jmail.AddAttachment(AddAttachment, true, null);
                //邮件内容
                Jmail.Body = body + t.ToString();
                //Jmail发送的方法
                Jmail.Send("smtp.163.com", false);
                Jmail.Close();
            }
            catch (Exception ex)
            {
                this.lblMessage.Text = ex.Message;
            }
        }