/// <summary> /// 发送邮件到指定邮箱 /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="to"></param> /// <returns></returns> public void SendAsync(string title, string body, string[] to) { lock (lockObject) { if (isSystemMail) { body += string.Format("<br/><br/>系统邮件,请勿直接回复!<span style=\"font-size:12px;\">({0})</span>", DateTime.Now); } SMTP smtp = new SMTP(this.mailFrom, to, title, body, this.smtpServer, userName, password); smtp.SMTPPort = this.smtpPort; smtp.MailDisplyName = this.displayName; smtp.IsBodyHtml = true; //启用线程池来实现异步发送 AsyncMailSender sender = new AsyncMailSender(mail => mail.SendAsync()); IAsyncResult result = sender.BeginInvoke(smtp, ar => { AsyncMailSender handler = ar.AsyncState as AsyncMailSender; if (handler != null) { handler.EndInvoke(ar); } }, sender); } }
/// <summary> /// 发送邮件到指定邮箱 /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="to"></param> /// <returns></returns> public SendResult Send(string title, string body, string[] to) { lock (lockObject) { if (isSystemMail) { body += string.Format("<br/><br/>系统邮件,请勿直接回复!<span style=\"font-size:12px;\">({0})</span>", DateTime.Now); } SMTP smtp = new SMTP(this.mailFrom, to, title, body, this.smtpServer, userName, password); smtp.SMTPPort = this.smtpPort; smtp.MailDisplyName = this.displayName; smtp.IsBodyHtml = true; return(smtp.Send()); } }
/// <summary> /// 发送邮件到指定邮箱 /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="to"></param> /// <returns></returns> public void SendAsync(string title, string body, string[] to) { lock (lockObject) { if (isSystemMail) body += string.Format("<br/><br/>系统邮件,请勿直接回复!<span style=\"font-size:12px;\">({0})</span>", DateTime.Now); SMTP smtp = new SMTP(this.mailFrom, to, title, body, this.smtpServer, userName, password); smtp.SMTPPort = this.smtpPort; smtp.MailDisplyName = this.displayName; smtp.IsBodyHtml = true; //启用线程池来实现异步发送 AsyncMailSender sender = new AsyncMailSender(mail => mail.SendAsync()); IAsyncResult result = sender.BeginInvoke(smtp, ar => { AsyncMailSender handler = ar.AsyncState as AsyncMailSender; if (handler != null) { handler.EndInvoke(ar); } }, sender); } }
/// <summary> /// 发送邮件到指定邮箱 /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="to"></param> /// <returns></returns> public SendResult Send(string title, string body, string[] to) { lock (lockObject) { if (isSystemMail) body += string.Format("<br/><br/>系统邮件,请勿直接回复!<span style=\"font-size:12px;\">({0})</span>", DateTime.Now); SMTP smtp = new SMTP(this.mailFrom, to, title, body, this.smtpServer, userName, password); smtp.SMTPPort = this.smtpPort; smtp.MailDisplyName = this.displayName; smtp.IsBodyHtml = true; return smtp.Send(); } }