Exemple #1
0
        public static bool SendSMS(SMSMessage message)
        {
            bool useNewSendMethod = bool.Parse(ConfigurationManager.AppSettings["UseNewSendMethod"]);

            if (useNewSendMethod)
            {
                return(SendNew(message));
            }
            else
            {
                return(SendOld(message));
            }
        }
Exemple #2
0
        // Created By: GA S. 10192006
        private static bool SendOld(SMSMessage message)
        {
            TxtConnect.TxtConnWS txtConn = new TxtConnect.TxtConnWS();
            string username     = ConfigurationManager.AppSettings["TxtConnUsername"];
            string password     = ConfigurationManager.AppSettings["TxtConnPassword"];
            string organization = ConfigurationManager.AppSettings["TxtConnOrganization"];
            string token        = string.Empty;
            string smsc_from    = ConfigurationManager.AppSettings["Mask"].Trim();
            string cmts         = ConfigurationManager.AppSettings["Mask"].Trim();
            bool   isSuccessful = false;

            if (txtConn.Url.StartsWith("https:"))
            {
                bool useProxy = bool.Parse(ConfigurationManager.AppSettings["UseProxy"].Trim());
                if (useProxy)
                {
                    int    proxyPort     = int.Parse(ConfigurationManager.AppSettings["ProxyPort"].Trim());
                    string proxyHost     = ConfigurationManager.AppSettings["ProxyHost"].Trim();
                    string proxyUsername = ConfigurationManager.AppSettings["ProxyUsername"].Trim();
                    string proxyPassword = ConfigurationManager.AppSettings["ProxyPassword"].Trim();
                    string proxyDomain   = ConfigurationManager.AppSettings["ProxyDomain"].Trim();

                    WebProxy          proxy   = new WebProxy(proxyHost, proxyPort);
                    NetworkCredential netCred = new NetworkCredential(proxyUsername, proxyPassword, proxyDomain);

                    proxy.Credentials = netCred;
                    txtConn.Proxy     = proxy;
                }
                #pragma warning disable
                ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                #pragma warning restore
            }

            // validate user
            DataSet ds = txtConn.ValidateUser(username, password, organization, false);

            if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
            {
                // login ok
                token = ds.Tables[0].Rows[0]["token"].ToString().Trim();

                DataSet mDs = new DataSet();
                mDs.Tables.Add();
                mDs.Tables[0].Columns.Add("mobile");
                mDs.Tables[0].Columns.Add("uniqueid");

                string[] recipients = message.Recipients.Split(new char[] { ',' });
                for (int i = 0; i < recipients.Length; i++)
                {
                    DataRow dr = mDs.Tables[0].NewRow();
                    dr["mobile"]   = recipients[i];
                    dr["uniqueid"] = i + 1;
                    mDs.Tables[0].Rows.Add(dr);
                }

                isSuccessful = txtConn.SendMessageList(token,
                                                       username,
                                                       message.Recipients,
                                                       message.Subject,
                                                       message.IncludeSubject,
                                                       message.Content,
                                                       message.Footer,
                                                       message.IncludeFooter,
                                                       smsc_from,
                                                       cmts,
                                                       100,
                                                       DateTime.Now.ToString("MM/dd/yy HH:mm"),
                                                       mDs);
            }
            else
            {
                // login failed
                isSuccessful = false;
            }

            return(isSuccessful);
        }
Exemple #3
0
        // Created By: GA S. 12142006
        private static bool SendNew(SMSMessage message)
        {
            TxtConnWS.TCWS txtConn      = new TxtConnWS.TCWS();
            string         username     = ConfigurationManager.AppSettings["TxtConnUsername"].Trim();
            string         password     = ConfigurationManager.AppSettings["TxtConnPassword"].Trim();
            string         organization = ConfigurationManager.AppSettings["TxtConnOrganization"].Trim();
            string         token        = string.Empty;
            string         smsc_from    = ConfigurationManager.AppSettings["Mask"].Trim();
            string         cmts         = ConfigurationManager.AppSettings["Mask"].Trim();
            bool           isSuccessful = false;

            txtConn.Url = ConfigurationManager.AppSettings["TxtConnWS.tcws"].Trim();

            #region Proxy and Certificate
            if (txtConn.Url.StartsWith("https:"))
            {
                bool useProxy = bool.Parse(ConfigurationManager.AppSettings["UseProxy"].Trim());
                if (useProxy)
                {
                    int    proxyPort     = int.Parse(ConfigurationManager.AppSettings["ProxyPort"].Trim());
                    string proxyHost     = ConfigurationManager.AppSettings["ProxyHost"].Trim();
                    string proxyUsername = ConfigurationManager.AppSettings["ProxyUsername"].Trim();
                    string proxyPassword = ConfigurationManager.AppSettings["ProxyPassword"].Trim();
                    string proxyDomain   = ConfigurationManager.AppSettings["ProxyDomain"].Trim();

                    WebProxy          proxy   = new WebProxy(proxyHost, proxyPort);
                    NetworkCredential netCred = new NetworkCredential(proxyUsername, proxyPassword, proxyDomain);

                    proxy.Credentials = netCred;
                    txtConn.Proxy     = proxy;
                }
                #pragma warning disable
                ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                #pragma warning restore
            }
            #endregion

            #region Validate User
            try
            {
                token = txtConn.ValidateUser(username, password, organization);
            }
            catch
            {
                return(false);
            }
            #endregion

            if (token.ToUpper().Trim() != "INVALID CREDENTIALS")
            {
                // login ok
                isSuccessful = txtConn.SendMessageList(token,
                                                       message.Recipients,
                                                       message.Content,
                                                       smsc_from,
                                                       cmts,
                                                       DateTime.Now.ToString("MM/dd/yy HH:mm"));
            }
            else
            {
                // login failed
                isSuccessful = false;
            }


            return(isSuccessful);
        }