예제 #1
0
 ///<summary>
 /// 邮件的发送
 ///</summary>
 public void Send()
 {
     try
     {
         if (mMailMessage != null)
         {
             mSmtpClient = new SmtpClient();
             //mSmtpClient.Host = "smtp." + mMailMessage.From.Host;
             mSmtpClient.Host = this.mSenderServerHost;
             mSmtpClient.Port = this.mSenderPort;
             mSmtpClient.UseDefaultCredentials = false;
             mSmtpClient.EnableSsl             = this.mEnableSsl;
             if (this.mEnablePwdAuthentication)
             {
                 System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
                 //mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
                 //NTLM: Secure Password Authentication in Microsoft Outlook Express
                 mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM");
             }
             else
             {
                 mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
             }
             mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
             mSmtpClient.Send(mMailMessage);
         }
     }
     catch (Exception ex)
     {
         ClassLoger.Error("EmailHelper.Send", ex);
         throw;
     }
 }
예제 #2
0
 public void Start()
 {
     ClassLoger.DEBUG("clearlogs/Start", "日志清理开始");
     th = new Thread(new ThreadStart(Worker));
     th.Start();
 }
예제 #3
0
        public string Get(string url, string Encode = "", int TimeOut = 6000, string cookies = "")
        {
            int errortimes = 4;

A:
            try
            {
                ClassLoger.Info("HttpUtils.GetAsync", url);
                System.Net.WebRequest wRequest = System.Net.WebRequest.Create(url);
                wRequest.Method = "GET";
                wRequest.UseDefaultCredentials = true;
                wRequest.Headers.Set(HttpRequestHeader.UserAgent, UserAgent);
                wRequest.Headers.Set(HttpRequestHeader.KeepAlive, "true");
                wRequest.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8");
                if (!Content_Encoding.IsNull())
                {
                    wRequest.Headers.Set(HttpRequestHeader.ContentEncoding, Content_Encoding);
                }
                if (!Content_Type.IsNull())
                {
                    wRequest.Headers.Set(HttpRequestHeader.ContentType, Content_Type);
                }
                if (!Accept.IsNull())
                {
                    wRequest.Headers.Set(HttpRequestHeader.Accept, Accept);
                }
                if (!Referer.IsNull())
                {
                    wRequest.Headers.Set(HttpRequestHeader.Referer, Referer);
                }

                switch (HttpProxy)
                {
                case HttpProxyType.Default:
                    break;

                case HttpProxyType.IE:
                    wRequest.Proxy = WebRequest.GetSystemWebProxy();
                    break;

                case HttpProxyType.None:
                    wRequest.Proxy = null;
                    break;
                }
                if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                {
                }
                wRequest.Timeout = TimeOut;
                if (!string.IsNullOrEmpty(cookies))
                {
                    wRequest.Headers.Set(HttpRequestHeader.Cookie, cookies);
                }
                Encoding encoder = Encoding.Default;
                if (!Encode.IsNull())
                {
                    encoder = Encoding.GetEncoding(Encode);
                }
                System.Net.WebResponse wResp      = wRequest.GetResponse();
                System.IO.Stream       respStream = wResp.GetResponseStream();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, encoder))
                {
                    return(reader.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                ClassLoger.Error("HTTPHelper.Get", ex);
                if (errortimes > 0)
                {
                    errortimes--;
                    goto A;
                }
            }
            return(string.Empty);
        }