日期:2014-05-19  浏览次数:20557 次

VS2003 C# 发送邮件老是失败,郁闷之极~~~!
#region   SendMail   自动发送邮件
///   <summary>
///  
///   </summary>
///   <param   name= "ls_Attach "> 邮件附件 </param>
///   <param   name= "ls_Cc "> 抄送副本 </param>
///   <param   name= "ls_Body "> 邮件正文 </param>
///   <param   name= "ls_From "> 发件人的地址 </param>
///   <param   name= "ls_Subject "> 电子邮件主题 </param>
///   <param   name= "ls_To "> 收件人地址 </param>
public   int   SendMail(System.Web.UI.HtmlControls.HtmlInputFile   HIF,string   ls_Cc,string   ls_Body,string   ls_From,string   ls_Subject,string   ls_To)
{
// System.Web.Mail.MailAttachment   mailAttach=new   MailAttachment(ls_Attach,System.Web.Mail.MailEncoding.Base64);//创建上传附件的对象

System.Web.Mail.MailMessage   mailMessage=new   MailMessage();//创建发送邮件的对象

mailMessage.Priority=System.Web.Mail.MailPriority.High;
mailMessage.BodyFormat=System.Web.Mail.MailFormat.Html;
mailMessage.BodyEncoding=System.Text.Encoding.ASCII;

// mailMessage.Attachments.Add(mailAttach); //邦定发送附件的对象
mailMessage.Attachments.Add(new   MailAttachment(HIF.PostedFile.FileName)); //添加附件
mailMessage.Cc=ls_Cc;

mailMessage.Body=ls_Body; //电子邮件正文

mailMessage.From=ls_From; //发件人的邮件地址
mailMessage.To=ls_To; //收件人地址
mailMessage.Subject=ls_Subject; //发件人的标题
try
{
System.Web.Mail.SmtpMail.SmtpServer= "127.0.0.1 ";
System.Web.Mail.SmtpMail.Send(mailMessage);
return   1;
}
catch
{
return   0;
}
}
#endregion

//-----------------------------------

开始调用
i=michael.SendMail(File1, " ", "hello   michael! ", "michael-007@tom.com ", "hello! ", "michael-007@tom.com ");
Response.Write(i.ToString());
注:1)、michael是我写的一个类,里面封装了上面的发送邮件的方法;
        2)、File1是我拉德一个File   Fields控件,用来上传附件

//--------------问题----------------
老是发送不成功,请问该如何解决?谢谢各位!

------解决方案--------------------
服务器需要验证
google!