用System.Web.Mail发邮件

private static int GoToSendMail(string Body,string To)
  {
   try
   {
    System.Web.Mail.MailMessage mm=new System.Web.Mail.MailMessage();
    mm.BodyFormat=System.Web.Mail.MailFormat.Html;
    mm.From=" [email protected] ";
    mm.To=To;
    mm.BodyEncoding=System.Text.Encoding.GetEncoding(936);
    mm.Subject="您好!我是梦猫.NET工作室希望与您携手一起成长。";
    mm.Body=Body;
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/sendusing "] = 2;
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/sendemailaddress "] = " [email protected]";// 发送地址;如果mm.From写了这儿可以不写这句
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/smtpaccountname "] = " [email protected] ";
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/sendusername "] = "XXX";//验证账号:发送者邮箱账号
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/sendpassword "] = "XXX"; //验证密码:发送者邮箱密码
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "] = 1; //验证级别0,1,2
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/languagecode "] = 0x0804;//语言代码
    mm.Fields[" http://schemas.microsoft.com/cdo/configuration/smtpserver "] = " SMTP.XXX.com "; //SMTP Server
    System.Web.Mail.SmtpMail.SmtpServer=" SMTP.XXX.com ";// 上句和这句重着,这句可以替代上句
    System.Web.Mail.SmtpMail.Send(mm);
    return 0;
   }
   catch(System.Exception e)
   {
    Response.Write(e.Message+e.StackTrace+e.Source);
    return -1;
   }
  }

你可能感兴趣的:(.net,工作,String,server,语言)