刚新接手一个网站,里面有一个发送E-mail的页面。现在客户那边说现在发不了E-mail了。我菜鸟一个。从来没做过B/S结构的东西。刚来公司才一个多月。请个位大侠帮看看:源码如下:
using System;
using System.Web;namespace EMailCommon
{
/// <summary>
/// Summary description for CDOSendMail.
/// </summary>
public class CDOSendMail
{
public CDOSendMail()
{
//
// TODO: Add constructor logic here
//
}

public static void sendMail(string mailFrom, string mailTo, string mailSubject, string mailBody)
{
try
{    
CDO.Message oMsg = new CDO.Message();
    
oMsg.From = mailFrom;       //"[email protected]";
oMsg.To = mailTo;           //"[email protected]";
oMsg.Subject = mailSubject; // "MailTest";
                                oMsg.HTMLBody = mailBody;   // "<html><body>Test</body></html>"; CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
          
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value= mailFrom; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value= mailTo;  //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="[email protected]";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="3308576636"; oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication. 
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value= "smtp.fabby.com";
//"smtp.21cn.com"; oFields.Update();
oMsg.BodyPart.Charset="ISO-8859-1";
oMsg.HTMLBodyPart.Charset="ISO-8859-1";  oMsg.Send();
oMsg = null;
}   
catch (Exception e)
{
throw e;
}
}
}
}

解决方案 »

  1.   

    对了。我Debug时throw 出来的错误是:The transport error code was 0x80070057.The server response was not available"。
      

  2.   

    did you install smtp service?
      

  3.   

    现在可能最好的方法还是用jmail
      

  4.   

    我安装smtp service了。服务器怎么配置呀!我也不会呀!请说的具体一些行吗?多谢了。因为这个网站是美国的。咱们上班美国那边就要下班了,沟通起来特别不方便。
      

  5.   

    首先你要知道CDO是基于smtp服务的,所以你先检查你的邮件服务器吧,
    至于代码,只要google一下CDO,n多
      

  6.   

    Imports System.Web.Mail    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim sMsg As String
            Try            sMsg = "dasfasdfsdafsdafdsafsd"            Dim objEmail As New MailMessage            objEmail.To = "[email protected]"            objEmail.From = "[email protected]"            objEmail.Subject = "insert"            objEmail.Body = sMsg            objEmail.BodyFormat = MailFormat.Text            SmtpMail.SmtpServer = "smtp.163.com"
                objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
                objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wtaoboy")
                objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*****")
                System.Threading.Thread.Sleep(1000)            SmtpMail.Send(objEmail)        Catch aa As Exception
                MsgBox("dsfasfdsa")
            End Try    End Sub
      

  7.   

    我建议你把报的错在百度或google上搜索一下
    没准能找到答案呢
      

  8.   

    问题解决了,是因为下面的这行语句。我把原来的2改为1就好用了。1表示走本地的SMTP
    oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=1;
    谢谢大家的参与。