Example #1
0
        public override void Send(MailEntity entity, Dictionary <string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string url;

            if (!parameters.TryGetValue("url", out url) || url == null || url.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'url' for restful mail sender.");
            }
            string method;

            if (!parameters.TryGetValue("method", out method) || method == null || method.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'method' for restful mail sender.");
            }

            SoapEntityMapping.Add <MailEntity>();
            SoapEntityMapping.Add <MailTemplateEntity>();
            SoapEntityMapping.Add <VariableTable>();
            SoapEntityMapping.Add <Variable>();
            SoapClient.Invoke(url, method, entity);
        }
        public override void Send(MailEntity entity, Dictionary <string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string url;

            if (!parameters.TryGetValue("url", out url) || url == null || url.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'url' for restful mail sender.");
            }
            string     methodStr;
            HttpMethod method;

            if (!parameters.TryGetValue("method", out methodStr) || methodStr == null || methodStr.Trim().Length <= 0 ||
                Enum.TryParse <HttpMethod>(methodStr, out method) == false ||
                Enum.IsDefined(typeof(HttpMethod), method) == false)
            {
                method = HttpMethod.Post;
            }
            string        formatStr;
            RequestFormat format;

            if (!parameters.TryGetValue("format", out formatStr) || formatStr == null || formatStr.Trim().Length <= 0 ||
                Enum.TryParse <RequestFormat>(formatStr, out format) == false ||
                Enum.IsDefined(typeof(RequestFormat), format) == false)
            {
                format = RequestFormat.Json;
            }

            RestClient client = new RestClient();

            client.Invoke(url, entity, method, format);
        }
        public override void Send(MailEntity entity, Dictionary<string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string url;
            if (!parameters.TryGetValue("url", out url) || url == null || url.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'url' for restful mail sender.");
            }
            string methodStr;
            HttpMethod method;
            if (!parameters.TryGetValue("method", out methodStr) || methodStr == null || methodStr.Trim().Length <= 0
                || Enum.TryParse<HttpMethod>(methodStr, out method) == false
                || Enum.IsDefined(typeof(HttpMethod), method) == false)
            {
                method = HttpMethod.Post;
            }
            string formatStr;
            RequestFormat format;
            if (!parameters.TryGetValue("format", out formatStr) || formatStr == null || formatStr.Trim().Length <= 0
                || Enum.TryParse<RequestFormat>(formatStr, out format) == false
                || Enum.IsDefined(typeof(RequestFormat), format) == false)
            {
                format = RequestFormat.Json;
            }

            RestClient client = new RestClient();
            client.Invoke(url, entity, method, format);
        }
Example #4
0
 public override void Send(MailEntity entity, Dictionary<string, string> parameters)
 {
     string queueId;
     if (!parameters.TryGetValue("queueId", out queueId) || queueId == null || queueId.Trim().Length <= 0)
     {
         throw new ConfigurationErrorsException("Not config 'queueId' for the queue mail sender.");
     }
     object publisher;
     MethodInfo method;
     GetPublishMethodInfo(queueId, out publisher, out method);
     method.Invoke(publisher, new object[] { entity });
 }
        public override void Send(MailEntity entity, Dictionary <string, string> parameters)
        {
            string queueId;

            if (!parameters.TryGetValue("queueId", out queueId) || queueId == null || queueId.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'queueId' for the queue mail sender.");
            }
            object     publisher;
            MethodInfo method;

            GetPublishMethodInfo(queueId, out publisher, out method);
            method.Invoke(publisher, new object[] { entity });
        }
Example #6
0
 public static void Send(MailEntity entity, MailSendType type = MailSendType.Smtp)
 {
     MailWrapper wrapper;
     if (!s_Cache.TryGetValue(type, out wrapper))
     {
         lock (s_SyncObj)
         {
             if (!s_Cache.TryGetValue(type, out wrapper))
             {
                 XmlNode section = ConfigurationManager.GetSection("mail") as XmlNode;
                 wrapper = new MailWrapper(section, type);
                 s_Cache.Add(type, wrapper);
             }
         }
     }
     wrapper.Send(entity);
 }
Example #7
0
        public static void Send(MailEntity entity, MailSendType type = MailSendType.Smtp)
        {
            MailWrapper wrapper;

            if (!s_Cache.TryGetValue(type, out wrapper))
            {
                lock (s_SyncObj)
                {
                    if (!s_Cache.TryGetValue(type, out wrapper))
                    {
                        XmlNode section = ConfigurationManager.GetSection("mail") as XmlNode;
                        wrapper = new MailWrapper(section, type);
                        s_Cache.Add(type, wrapper);
                    }
                }
            }
            wrapper.Send(entity);
        }
        public override void Send(MailEntity entity, Dictionary <string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string address;

            if (!parameters.TryGetValue("address", out address))
            {
                throw new ConfigurationErrorsException("Not config 'address' for smtp mail sender.");
            }
            int    port;
            string portStr;

            if (!parameters.TryGetValue("port", out portStr) || !int.TryParse(portStr, out port) || port <= 0)
            {
                port = 25;
            }
            string username;

            if (!parameters.TryGetValue("username", out username) || username == null || username.Trim().Length <= 0)
            {
                username = string.Empty;
            }
            string password;

            if (!parameters.TryGetValue("password", out password) || password == null || password.Trim().Length <= 0)
            {
                password = string.Empty;
            }
            bool   enableSsl;
            string enableSslStr;

            if (!parameters.TryGetValue("enableSsl", out enableSslStr) || !bool.TryParse(enableSslStr, out enableSsl))
            {
                enableSsl = false;
            }
            SendMail(entity.FromAddress, entity.FromDisplay,
                     entity.ToAddressList == null ? null : entity.ToAddressList.ToArray(),
                     entity.CcAddressList == null ? null : entity.CcAddressList.ToArray(),
                     entity.BccAddressList == null ? null : entity.BccAddressList.ToArray(),
                     entity.Subject, entity.Body, null, entity.Charset, entity.IsBodyHtml, entity.Priority, address, port, username, password, enableSsl);
        }
Example #9
0
 public static void Send(string fromAddress, string fromDisplay, List<string> toAddressList, List<string> ccAddressList,
     List<string> bccAddressList, string subject, string body, Encoding charset, bool isBodyHtml = true,
     MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp)
 {
     MailEntity entity = new MailEntity
     {
         FromAddress = fromAddress,
         FromDisplay = fromDisplay,
         ToAddressList = toAddressList,
         CcAddressList = ccAddressList,
         BccAddressList = bccAddressList,
         Subject =subject,
         Body = body,
         Charset = charset,
         IsBodyHtml = isBodyHtml,
         Priority = priority
     };
     Send(entity, type);
 }
Example #10
0
        public static void Send(string fromAddress, string fromDisplay, List <string> toAddressList, List <string> ccAddressList,
                                List <string> bccAddressList, string subject, string body, Encoding charset, bool isBodyHtml = true,
                                MailPriority priority = MailPriority.Normal, MailSendType type = MailSendType.Smtp)
        {
            MailEntity entity = new MailEntity
            {
                FromAddress    = fromAddress,
                FromDisplay    = fromDisplay,
                ToAddressList  = toAddressList,
                CcAddressList  = ccAddressList,
                BccAddressList = bccAddressList,
                Subject        = subject,
                Body           = body,
                Charset        = charset,
                IsBodyHtml     = isBodyHtml,
                Priority       = priority
            };

            Send(entity, type);
        }
Example #11
0
 public override void Send(MailEntity entity, Dictionary<string, string> parameters)
 {
     if (entity == null)
     {
         return;
     }
     string address;
     if (!parameters.TryGetValue("address", out address))
     {
         throw new ConfigurationErrorsException("Not config 'address' for smtp mail sender.");
     }
     int port;
     string portStr;
     if (!parameters.TryGetValue("port", out portStr) || !int.TryParse(portStr, out port) || port <= 0)
     {
         port = 25;
     }
     string username;
     if (!parameters.TryGetValue("username", out username) || username == null || username.Trim().Length <= 0)
     {
         username = string.Empty;
     }
     string password;
     if (!parameters.TryGetValue("password", out password) || password == null || password.Trim().Length <= 0)
     {
         password = string.Empty;
     }
     bool enableSsl;
     string enableSslStr;
     if (!parameters.TryGetValue("enableSsl", out enableSslStr) || !bool.TryParse(enableSslStr, out enableSsl))
     {
         enableSsl = false;
     }
     SendMail(entity.FromAddress, entity.FromDisplay,
         entity.ToAddressList == null ? null : entity.ToAddressList.ToArray(),
         entity.CcAddressList == null ? null : entity.CcAddressList.ToArray(),
         entity.BccAddressList == null ? null : entity.BccAddressList.ToArray(),
         entity.Subject, entity.Body, null, entity.Charset, entity.IsBodyHtml, entity.Priority, address, port, username, password, enableSsl);
 }
Example #12
0
        public override void Send(MailEntity entity, Dictionary<string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string url;
            if (!parameters.TryGetValue("url", out url) || url == null || url.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'url' for restful mail sender.");
            }
            string method;
            if (!parameters.TryGetValue("method", out method) || method == null || method.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'method' for restful mail sender.");
            }

            SoapEntityMapping.Add<MailEntity>();
            SoapEntityMapping.Add<MailTemplateEntity>();
            SoapEntityMapping.Add<VariableTable>();
            SoapEntityMapping.Add<Variable>();
            SoapClient.Invoke(url, method, entity);
        }
Example #13
0
 public abstract void Send(MailEntity entity, Dictionary <string, string> parameters);
Example #14
0
 public void Send(MailEntity entity)
 {
     if (m_Config == null || m_Config.Count <= 0)
     {
         throw new ApplicationException("not config any node to send mail for " + m_MailSendType.ToString());
     }
     int count = 0;
     for (int i = m_StartIndex; i < m_Config.Count; i++)
     {
         count++;
         if (m_ErrorTimeList[i].AddSeconds(m_RecoverSeconds) > DateTime.Now)
         {
             continue;
         }
         try
         {
             m_Mail.Send(entity, m_Config[i]);
             m_StartIndex = (i + 1 >= m_Config.Count ? 0 : i + 1);
             return;
         }
         catch (Exception ex)
         {
             m_ErrorTimeList[i] = DateTime.Now;
             m_ErrorInfoList[i] = ex.Message;
             if (count >= m_Config.Count)
             {
                 throw;
             }
         }
     }
     int c = m_Config.Count - count;
     for (int i = 0; i < c; i++)
     {
         count++;
         if (m_ErrorTimeList[i].AddSeconds(m_RecoverSeconds) > DateTime.Now)
         {
             continue;
         }
         try
         {
             m_Mail.Send(entity, m_Config[i]);
             m_StartIndex = (i + 1 >= m_Config.Count ? 0 : i + 1);
             return;
         }
         catch (Exception ex)
         {
             m_ErrorTimeList[i] = DateTime.Now;
             m_ErrorInfoList[i] = ex.Message;
             if (count >= m_Config.Count)
             {
                 throw;
             }
         }
     }
     StringBuilder sb = new StringBuilder();
     sb.Append("[" + DateTime.Now + "]All nodes to send mail by " + m_MailSendType.ToString() + " are failed. Failed detail info:");
     for (int i = 0; i < m_Config.Count; i++)
     {
         sb.Append("\r\n(" + i + ") - [" + m_ErrorTimeList[i] + "] : " + m_ErrorInfoList[i]);
     }
     throw new ApplicationException(sb.ToString());
 }
Example #15
0
        public void Send(MailEntity entity)
        {
            if (m_Config == null || m_Config.Count <= 0)
            {
                throw new ApplicationException("not config any node to send mail for " + m_MailSendType.ToString());
            }
            int count = 0;

            for (int i = m_StartIndex; i < m_Config.Count; i++)
            {
                count++;
                if (m_ErrorTimeList[i].AddSeconds(m_RecoverSeconds) > DateTime.Now)
                {
                    continue;
                }
                try
                {
                    m_Mail.Send(entity, m_Config[i]);
                    m_StartIndex = (i + 1 >= m_Config.Count ? 0 : i + 1);
                    return;
                }
                catch (Exception ex)
                {
                    m_ErrorTimeList[i] = DateTime.Now;
                    m_ErrorInfoList[i] = ex.Message;
                    if (count >= m_Config.Count)
                    {
                        throw;
                    }
                }
            }
            int c = m_Config.Count - count;

            for (int i = 0; i < c; i++)
            {
                count++;
                if (m_ErrorTimeList[i].AddSeconds(m_RecoverSeconds) > DateTime.Now)
                {
                    continue;
                }
                try
                {
                    m_Mail.Send(entity, m_Config[i]);
                    m_StartIndex = (i + 1 >= m_Config.Count ? 0 : i + 1);
                    return;
                }
                catch (Exception ex)
                {
                    m_ErrorTimeList[i] = DateTime.Now;
                    m_ErrorInfoList[i] = ex.Message;
                    if (count >= m_Config.Count)
                    {
                        throw;
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("[" + DateTime.Now + "]All nodes to send mail by " + m_MailSendType.ToString() + " are failed. Failed detail info:");
            for (int i = 0; i < m_Config.Count; i++)
            {
                sb.Append("\r\n(" + i + ") - [" + m_ErrorTimeList[i] + "] : " + m_ErrorInfoList[i]);
            }
            throw new ApplicationException(sb.ToString());
        }
Example #16
0
 public abstract void Send(MailEntity entity, Dictionary<string, string> parameters);