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("失败");
}
// 读取模板文件
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("失败");
}