我用win2003自带的smtp服务器写了一个邮件发送的实例
但是老是收不到信
请指教如何解决:
代码如下:
private void Enter_Click(object sender,EventArgs e)
{
//下面一段设置信件内容
MailMessage objMail = new MailMessage();            
objMail.From=mailFrom.Text;                        //发件人地址
objMail.To=mailTo.Text;                           //收件人地址
objMail.Subject=Subject.Text;                     //信件主题
objMail.Body=Body.Text;                           //信件内容
objMail.BodyFormat = MailFormat.Text;             //信件格式      
//下面一段先将客户端的文件上传到服务器端,关于上传可以参考3-4.aspx。
string filename,filepath; 
filename= Path.GetFileName(uploadfile.PostedFile.FileName);     //获取上传文件名称        
filepath= "C:\\Inetpub\\wwwroot\\asp.netC\\chapter4\\upload\\" + filename; 
uploadfile.PostedFile.SaveAs(filepath);           //保存上传文件         
//下面一段添加附件,注意这里上传到服务器端的文件。
MailAttachment objAttach = new MailAttachment(filepath);    //建立附件对象实例
objMail.Attachments.Add(objAttach);      //添加附件
//下面一段发送信件
SmtpMail.SmtpServer="localhost";      //设置发信服务器为本机
//SmtpMail.Send(objMail);  //发送信件
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication 
 objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "bbb"); //set your username here 
 objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "ccc"); //set your password here 
 SmtpMail.SmtpServer="mail.163.com"; message.Text="成功发送";  //显示成功发送信息
}
显示成功但收不到信件。

解决方案 »

  1.   

    改成下面的试下: private void btnSend_Click(object sender, System.EventArgs e)
    {
    try 
    {
    MailMessage Message = new MailMessage(); if( this.chkRequireLogin.Checked ) 
    {
    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" ); //basic authentication
    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", txtUserName.Text ); //set your username here
    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtPassword.Text ); //set your password here
    //set time out
    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60); 
    }
    Message.To = txtTo.Text;
    Message.Cc = txtCC.Text;
    Message.Bcc = txtBCC.Text;
    Message.From = txtFrom.Text;
    Message.Subject = txtSubject.Text;
    Message.BodyFormat = (MailFormat)System.Enum.Parse(typeof(MailFormat), ddlMailFormat.SelectedValue );
    Message.Body = txtMessage.Text; SmtpMail.SmtpServer = txtServer.Text;//eg:  smtp.163.com
    SmtpMail.Send(Message); lblResult.Text = "邮件发送成功!";
    }
    catch( Exception ex ) 
    {
    lblResult.Text = ex.ToString();
    }
    }
      

  2.   

    SmtpMail.SmtpServer="localhost";
    你设置邮件服务器为本机,但你本机有邮件服务器吗?
    你还是老实设置邮件服务器的域名.
      

  3.   

    SmtpMail.SmtpServer="mail.163.com";改成SmtpMail.SmtpServer="localhost";  看看
      

  4.   

    我本机有邮件服务器的
    但是我想用163.com的发
    在本地测试的时候可以成功发送
    但是上传到服务器之后就不能发了
    不知道是什么原因!!
      

  5.   

    服务器上不一定安装有smtp服务
    所以最好使用jmail这样的发信组件
      

  6.   

    。net内置的邮件发送只能使用本机的CDO组件来发送,如果想使用其他smtp,请将jmail.dll导入.net然后使用。你的程序所以无法使用163发邮件。
      

  7.   

    修正一下,是使用其他带有身份验证的smtp服务器。Sorry,差点误入子弟了。
      

  8.   

    如果有smtp服务器的话
    那么
    ("http://schemas.microsoft.com/cdo/configuration/sendusername", txtUserName.Text ); //set your username here
    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtPassword.Text ); //set your password here
    这些东西该如何设置啊?
    谢谢!!!
      

  9.   

    txtUserName.Text   邮箱用户名
    txtPassword.Text   邮箱密码