噢!代码如下
   string str="文本格式";
   MailMessage MyMsg = new MailMessage();
   MyMsg.From = Tbfrom.Text;
   MyMsg.To = Tbto.Text;
   MyMsg.Cc = "";
   MyMsg.Bcc = "";
   MyMsg.Subject = Tbsubject.Text;
   //MyMsg.Priority = (MailPriority)ddlPriority.SelectedIndex;
  //MyMsg.BodyFormat= (MailFormat)str;
  MyMsg.Body = Tbmsgtext.Text;
           
  string strPath;
  strPath=Server.MapPath(".")+"\\warning.gif";
  MyMsg.Attachments.Add(new MailAttachment(strPath));
  try
 {
      SmtpMail.Send(MyMsg);
      Label5.Text="发送成功!";
  }
  catch
 {
    Label5.Text="发送失败!";
 }

解决方案 »

  1.   

    代码里好象没有邮件服务器的地址设定。
    其一:
    MailMessage mm = new MailMessage();
    mm.From = "##@hotmail.com";
    mm.To = ""#####@hotmail.com";
    mm.Subject = "呵呵!";
    mm.Body = "**";
    mm.Attachments.
    SmtpMail.SmtpServer ="10.88.0.7";
    SmtpMail.Send(mm);
    this.Response.Write("<script>alert(\"发送成功!\")</script>");
    其中SmtpMail.SmtpServer ="10.88.0.7";是指LAN内邮件服务器地址。
    其二:
    public bool sendMail()
    {
    MessageClass email = new MessageClass();
    email.Logging = true;
    email.Silent = true;
    email.MailServerUserName = "[email protected]";
    email.MailServerPassWord = "124";
    email.From = "[email protected]";
    email.Subject = "jmail";
    email.AddAttachment("c:\\test.xml",true,"");
    email.Body = "test jmail send mail";
    email.AddRecipient("[email protected]", "abc", null);
    return email.Send("mail.163.com", false) 
    }