using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;
namespace IPandLog
{
class SendEmail
{
public bool sendRandomCode(string strEmail, string strRandomCode)
{
//发送邮箱
string Email = "xxxxx@163.com";
string password = "xxxx";
Encoding Encode = Encoding.UTF8;
MailMessage Message = new System.Net.Mail.MailMessage();
Message.From = new MailAddress(Email,"ken公司",Encode);
Message.To.Add(new MailAddress(strEmail,"尊敬的用户",Encode));
Message.Subject = "找回密码";
Message.SubjectEncoding = Encode;
//CC为抄送,即发给用户的同时,再发送给Email
// Message.CC.Add(new MailAddress(Email,"抄送ken"));
StringBuilder mailContent = new StringBuilder();
mailContent.Append("尊敬的用户:<br/> ");
mailContent.Append(" 您好!你于");
mailContent.Append(DateTime.Now.ToLongTimeString());
mailContent.Append("申请找回密码,请输入下面的6位数随机码到页面的文本框: " + strRandomCode);
Message.Body = mailContent.ToString();
Message.BodyEncoding = Encode;
Message.IsBodyHtml = true;
try
{
SmtpClient smtp = new SmtpClient("smtp.163.com", 25);
smtp.Credentials = new NetworkCredential(Email, password);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(Message);
}
catch (Exception e)
{
return false;
}
finally
{
Message.Dispose();
}
return true;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;
namespace IPandLog
{
class SendEmail
{
public bool sendRandomCode(string strEmail, string strRandomCode)
{
//发送邮箱
string Email = "xxxxx@163.com";
string password = "xxxx";
Encoding Encode = Encoding.UTF8;
MailMessage Message = new System.Net.Mail.MailMessage();
Message.From = new MailAddress(Email,"ken公司",Encode);
Message.To.Add(new MailAddress(strEmail,"尊敬的用户",Encode));
Message.Subject = "找回密码";
Message.SubjectEncoding = Encode;
//CC为抄送,即发给用户的同时,再发送给Email
// Message.CC.Add(new MailAddress(Email,"抄送ken"));
StringBuilder mailContent = new StringBuilder();
mailContent.Append("尊敬的用户:<br/> ");
mailContent.Append(" 您好!你于");
mailContent.Append(DateTime.Now.ToLongTimeString());
mailContent.Append("申请找回密码,请输入下面的6位数随机码到页面的文本框: " + strRandomCode);
Message.Body = mailContent.ToString();
Message.BodyEncoding = Encode;
Message.IsBodyHtml = true;
try
{
SmtpClient smtp = new SmtpClient("smtp.163.com", 25);
smtp.Credentials = new NetworkCredential(Email, password);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(Message);
}
catch (Exception e)
{
return false;
}
finally
{
Message.Dispose();
}
return true;
}
}
}