using System.Net.Mail;
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//MailMessage msg = new MailMessage(); //创建MailMessage类的对象
StringWriter strWriter = new StringWriter(); //创建StringWriter类的对象
HtmlTextWriter htmltxtwriter = new HtmlTextWriter(strWriter); //创建HtmlTextWriter类的对象
htmltxtwriter.RenderBeginTag("html"); //往HtmlTextWriter输出流中写入HTML元素的开始标记
htmltxtwriter.RenderBeginTag("head");
htmltxtwriter.RenderBeginTag("title");
htmltxtwriter.Write("Thank You!");
htmltxtwriter.RenderEndTag(); //往HtmlTextWriter输出流中写入HTML元素的结束标记,此是标题的结束
htmltxtwriter.RenderEndTag(); //此是头的结束
htmltxtwriter.RenderBeginTag("body");
htmltxtwriter.WriteLine("Thank you for registering with WebShoppe Site!");
htmltxtwriter.RenderEndTag(); //此是体的结束
htmltxtwriter.RenderEndTag(); //此是html的结束
//msg.From = new MailAddress("xxx@gmail.com"); //发送者地址
//msg.To.Add("xxx@hotmail.com"); //接收者地址
//msg.Subject = "Thanks for registering"; //邮件的主题
//msg.Body = "测试邮件发送示例"; //邮件的内容
//msg.IsBodyHtml = true; //指定信息的主体格式为HTML格式
//SmtpClient smtp = new SmtpClient();
//smtp.Host = "smtp.gmail.com"; //发送邮件服务器SMTP地址
//smtp.EnableSsl = true;
//smtp.Port = 587; //SMTP端口 465
//smtp.Credentials = new System.Net.NetworkCredential("ddd", "123456"); //chenjun:发送邮件的用户名;123:发送邮件的密码
//smtp.Send(msg); //发送e-mail信息
//Response.Write("<script>alert('发送成功')</script>");
//-------------------2--------------------------------
MailMessage msg = new MailMessage(); //创建MailMessage类的对象
msg.From = new MailAddress("it@hhh.com"); //发送者地址
msg.To.Add("me@hhh.com"); //接收者地址
msg.CC.Add(new MailAddress("xxx@gmail.com;xxx@hotmail.com"));//很奇怪,不能发送给多个用户的,把它设为一个用户就能发送了
//msg.CC.Add("it@hhh.com");//.Add("z@gmail.com,it@hhh.com");
msg.Subject = "Thanks for registering"; //邮件的主题
msg.Body = "<HTML><HEAD><TITLE> New Document </TITLE></HEAD> <BODY><b>测试邮件发送示例</b></BODY></HTML>"; //邮件的内容
msg.IsBodyHtml = true; //指定信息的主体格式为HTML格式
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.heraldata.com"; //发送邮件服务器SMTP地址
//smtp.EnableSsl = true;
smtp.Port = 2025; //SMTP端口 465
smtp.Credentials = new System.Net.NetworkCredential("it@hhhh.com", "123456"); //chenjun:发送邮件的用户名;123:发送邮件的密码
smtp.Send(msg); //发送e-mail信息
Response.Write("<script>alert('发送成功')</script>");
//----------------------------2 end ---------------
}
catch (Exception ex)
{
Response.Write(ex.Message);
}