/ C#

C#发送email

还是之前的那个监控项目,当目标网站出现异常,或者从异常恢复时,就发一封邮件给网站主人。 需要的库:using System.Net.Mail;

MailMessage myMail = new MailMessage(); myMail.From = new MailAddress("leo108@stuhack.com"); //发送email myMail.To.Add(new MailAddress("leo108@stuhack.com")); //目标email myMail.Subject = ti; myMail.SubjectEncoding = Encoding.UTF8; myMail.Body = con; myMail.BodyEncoding = Encoding.UTF8; myMail.IsBodyHtml = false; myMail.Priority = MailPriority.High; SmtpClient send = new SmtpClient(); send.Host = "smtp.qq.com"; //smtp地址 send.Port = 25; //smtp端口,默认25 send.Credentials = new NetworkCredential("leo108@stuhack.com", "123456"); //帐号&密码 send.DeliveryMethod = SmtpDeliveryMethod.Network; send.EnableSsl = true; //是否开启ssl登陆 send.Send(myMail);

C#发送email
Share this