话不多说,直接上代码
//邮件提醒
string Body = @"Dear " + list.Rows[i]["people"] + ":<br>您负责的客户:<span style=‘color:red;‘>" + list.Rows[i]["CustomerName"].ToString() + "</span>;项目:<span style=‘color:red;‘>" + list.Rows[i]["EntryName"].ToString() + @"</span>;将于<span style=‘color:red;‘>" + Convert.ToDateTime(list.Rows[i]["collectDate"]).ToString("yyyy-MM-dd") + "</span>号到期,请提醒缴费;<br><span style=‘color:red;‘>(系统邮件,请勿回复!)</span>";
string Email = “发送邮件的邮箱”;
string Code =“邮箱授权码”;
string Host = “smtp.qq.com”;//qq邮箱是smtp.qq.com,如果你使用的是126邮箱,就是smtp.126.com。
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(Email);
mailMessage.To.Add(new MailAddress("接收邮件的邮箱"));
mailMessage.Subject = "业务收费提醒"; //邮件标题
mailMessage.Body = Body; //邮件主题内容
mailMessage.IsBodyHtml = true; // 这句就是邮件内容可以是HTML格式,如果没有这句,HTML格式会无效
SmtpClient client = new SmtpClient();
client.Host = Host;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(Email, Code);
client.Send(mailMessage);
第一次发表,不好的地方请见谅,让我们一起成长吧!