标签:内容 from text send 成功 sub 构造 smtp for
//创建邮件服务器对象
SmtpClient smtp = new SmtpClient("smtp.sina.cn");
//创建发件人对象
MailAddress from = new MailAddress("18560812711@sina.cn");
//创建收件人对象
MailAddress to = new MailAddress(textBox1.Text);
//创建邮件对象,构造函数中传入发件人和收件人
MailMessage mess = new MailMessage(from, to);
//设置邮件的标题
mess.Subject = "【阿狸粑粑的验证码邮件】";
string aaa = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
Random r = new Random();
for (int i = 0; i < 16; i++)
{
yzm += aaa.Substring(r.Next(0, aaa.Length), 1);
}
//设置邮件的内容
mess.Body = "您的验证码为:" + yzm + ",请在20分钟内验证,系统邮件请勿回复!";
//创建互联网安全证书
NetworkCredential cred = new NetworkCredential("18560812711@sina.cn", "hq1234561");
//将证书绑定到服务器对象以便服务器验证
smtp.Credentials = cred;
//通过服务器对象将邮件发送出去
smtp.Send(mess);
MessageBox.Show("邮件发送成功,请尽快验证!");
标签:内容 from text send 成功 sub 构造 smtp for
原文地址:http://www.cnblogs.com/sistrong-5880558/p/7931836.html