private void AppendNotification(MailNotifyInfo mailNotifyInfo) { lock (this.m_lockObject) { this.m_mailNotifyInfos.AddLast(mailNotifyInfo); if (this.m_mailNotifyInfos.Count != 0) { this.m_threadEvent.Set(); } } }
public void MailSender(MailNotifyInfo e) { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(e.To); msg.From = new MailAddress("*****@*****.**", "xm_mis", System.Text.Encoding.UTF8); msg.Subject = e.Subject; msg.SubjectEncoding = System.Text.Encoding.UTF8; //邮件标题编码 msg.Body = e.Body; msg.BodyEncoding = System.Text.Encoding.UTF8; //邮件内容编码 msg.IsBodyHtml = false; //是否是HTML邮件 msg.Priority = MailPriority.High; //邮件优先级 SmtpClient client = new SmtpClient(); //client.Credentials = new System.Net.NetworkCredential("playstation.gui", "seiyali_122278");//("*****@*****.**", "seiyali_122278"); //client.Host = "smtp.gmail.com"; //client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("mis", "123456");//("*****@*****.**", "seiyali_122278"); client.Host = "serv.xmel.sh.cn"; client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); object userState = msg; try { client.SendAsync(msg, userState); } catch (Exception ex) { //Console.WriteLine("Exception caught in CreateTestMessage3(): {0}", // ex.ToString()); ex.ToString(); } }
private void ThreadStart() { while (true) { this.m_threadEvent.WaitOne(); MailNotifyInfo mailNotifyInfo = this.m_mailNotifyInfos.First.Value; sendMail toSend = new sendMail(); toSend.MailSender(mailNotifyInfo); lock (this.m_lockObject) { this.m_mailNotifyInfos.Remove(mailNotifyInfo); if (this.m_mailNotifyInfos.Count == 0) { this.m_threadEvent.Reset(); } } } }
public void NewMail(string to, string subject, string body) { MailNotifyInfo info = new MailNotifyInfo(to, subject, body); AppendNotification(info); }