SmtpClient client = new SmtpClient("smtp.163.com"); client.Credentials = new NetworkCredential("tongshuai2014@163.com","****"); MailAddress from = new MailAddress("tongshuai2014@163.com", "梦醒心晴", System.Text.Encoding.UTF8); MailAddress to = new MailAddress(TextBox1.Text); MailMessage message = new MailMessage(from, to); message.Body = TextBox3.Text; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = TextBox2.Text; message.SubjectEncoding = System.Text.Encoding.UTF8; try { client.Send(message); } catch { Label1.Text = "发送失败"; }
引入名字空间
using System.Net.Mail;
using System.Net;
推荐使用163 sina邮箱
上面的虽然写着简单点,但是问题却有些严重,比如body中的格式是html的话,发送的信息就会直接进到垃圾箱里,很惨的,在网上找了找,找到一个叫JMail的邮件组件,在这里提供一个实例代码,点击这里下载