用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="
XXX@XXX.com ";
    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 "] = " XXX@XXX.com";// 发送地址;如果mm.From写了这儿可以不写这句
    mm.Fields["
http://schemas.microsoft.com/cdo/configuration/smtpaccountname "] = " XXX@XXX.com ";
    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;
   }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值