.net邮件发送实例 邮件内容为网页模板

.net邮件发送实例 邮件内容为网页模板

2009-07-03 09:31:01|  分类: .NET|字号 订阅

 
 
 Encoding encoding = Encoding.GetEncoding("gb2312");
        // 读取模板文件
        string ModelTemp = HttpContext.Current.Server.MapPath("email.html");
        StreamReader sr = null;        
        string str = "";
        try
        {
            sr = new StreamReader(ModelTemp, encoding);
            str = sr.ReadToEnd(); // 读取文件
        }
        catch (Exception exp)
        {
            HttpContext.Current.Response.Write(exp.Message);
            HttpContext.Current.Response.End();
            sr.Close();
        }    
        str = str.Replace("password", "abcdefg");      
        SmtpClient client = new SmtpClient("smtp.163.com");
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential("jialeifei@163.com","789789789");
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        MailMessage message = new MailMessage("jialeifei@163.com", "smudddnui@126.com", "你的密码", str);
        message.BodyEncoding = Encoding.UTF8;
        message.IsBodyHtml = true;
        try
        {
            client.Send(message);
            Response.Write("成功");
        }
        catch
        {
            Response.Write("失败");
        }
上一篇:CF 584B Kolya and Tanya


下一篇:SQL Server中NULL的一个测试