Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recipients">收件人</param>
        /// <param name="subject">主题</param>
        /// <param name="body">内容</param>
        public void SendMail(string recipients, string subject, string body)
        {
            SmtpClient mailClient = new SmtpClient(_mailServer, 587);

            mailClient.Credentials = new NetworkCredential(_mailName, _mailPassword);
            MailMessage mailMessage = new MailMessage(_mailName, recipients, subject, body);

            mailMessage.BodyEncoding = Encoding.UTF8;
            //mailClient.Timeout = 5000;
            //mailClient.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
            mailMessage.IsBodyHtml = true;
            try
            {
                //mailClient.Send(mailMessage);
                mailClient.Send(mailMessage);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    LogHelp.WriteLog(ex.InnerException.Message, "EmailLog");
                }
                else
                {
                    LogHelp.WriteLog(ex.Message, "EmailLog");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 根据 key来提供 全局唯一的引用类型 通常用来给特定的管道 加属于自己的事务锁防止并发
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetDicValue(string key)
        {
            if (!(dic.ContainsKey(key)))
            {
                lock (dicLock) //加锁 再判断一次 确保 对象唯一不会被覆盖
                {
                    if (!(dic.ContainsKey(key)))
                    {
                        dic[key] = new object();
                        LogHelp.WriteLog(DateTime.Now + ": 创建了 一个全局锁对象 对象key为" + key, ApiFileDirectoryPara.LockDir);
                    }
                }
            }

            return(dic[key]);
        }