该方式直接保存为HTML文件,也可以是文本文件,其它格式效果不是很好
MailMessage mmsg = new MailMessage();
mmsg.Subject = "邮件标题";
mmsg.Body = "邮件内容";
mmsg.To.Add("accept@qq.com");//接收邮箱
byte[] bytes = System.Text.Encoding.Default.GetBytes
(@"<table><tr><td width=150>1234567891234567
</td><td width=80>12345678</td></tr></table>");
MemoryStream ms = new MemoryStream(bytes);
ContentType ct = new ContentType();
//附件文件类型
ct.MediaType = MediaTypeNames.Text.Html;
//附件名称,可以是其它后缀名
ct.Name = "附件名称" + DateTime.Now.ToString() + ".html";
mmsg.Attachments.Add(new Attachment(ms, ct));
//SMTP简单邮件协议
System.Net.Mail.SmtpClient sc
= new System.Net.Mail.SmtpClient();
sc.Host = "127.0.0.1";//主机地址
sc.Port = 25;//端口
//发送邮箱账号和密码
sc.Credentials =
new System.Net.NetworkCredential("account", "password");
//发送邮箱
mmsg.From = new MailAddress("account@qq.com");
sc.Send(mmsg);
//释放流资源
ms.Close();
ms.Dispose();