コード例 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            //using (System.Net.WebClient client = new System.Net.WebClient())
            //{
            //    try
            //    {
            //        string url = " http://smsc.vianett.no/v3/send.ashx?" +
            //            "src=" + txtPhoneNumber.Text + "&" +
            //            "dst=" + txtPhoneNumber.Text + "&" +
            //            "msg=" + System.Web.HttpUtility.UrlEncode(txtmessage.Text,System.Text.Encoding.GetEncoding("ISO-8859-1")) + "" +
            //            "username="******"&" +
            //            "password="******"ok"))
            //            MessageBox.Show("Your Message has been Successfully Sent.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        else
            //            MessageBox.Show("Message Send Failure.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    }
            //    catch (Exception ex)
            //    {

            //        MessageBox.Show(ex.Message,"message",MessageBoxButtons.OK,MessageBoxIcon.Error);
            //    }
            //}
            //Set parameters
            string username        = "******";
            string password        = "******";
            string msgsender       = "966508218155";
            string destinationaddr = txtPhoneNumber.Text;;
            string message         = txtmessage.Text;
            // Create ViaNettSMS object with username and password
            ViaNettSMS s = new ViaNettSMS(username, password);

            // Declare Result object returned by the SendSMS function
            ViaNettSMS.Result result;
            try
            {
                // Send SMS through HTTP API
                result = s.sendSMS(msgsender, destinationaddr, message);
                // Show Send SMS response
                if (result.Success)
                {
                    MessageBox.Show("Message successfully sent");
                }
                else
                {
                    MessageBox.Show("Received error: " + result.ErrorCode + " " + result.ErrorMessage);
                }
            }
            catch (System.Net.WebException ex)
            {
                //Catch error occurred while connecting to server.
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private static void SendSms(INotificationRepository repo, IList <UserView> users, Notification notify)
        {
            string error     = null;
            string username  = "******";
            string password  = "******";
            string msgsender = "4700000000"; // "DEMO374733";
            //string destinationaddr = "4560991000";

            // Create ViaNettSMS object with username and password
            ViaNettSMS s = new ViaNettSMS(username, password);

            // Declare Result object returned by the SendSMS function
            ViaNettSMS.Result result;

            foreach (var user in users)
            {
                try
                {
                    // Send SMS through HTTP API
                    result = s.sendSMS(msgsender, user.PhoneNumber, notify.Message);
                    // Show Send SMS response
                    if (result.Success)
                    {
                        error = null;
                    }
                    else
                    {
                        error = "Received error: " + result.ErrorCode + " " + result.ErrorMessage;
                    }
                    error = null;
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }


                repo.Add(new SmsLog
                {
                    Error       = error,
                    NotificatId = notify.Id,
                    Notificat   = notify.Id == 0 ? notify : null,
                    SentOk      = error == null,
                    SentTime    = DateTime.Now,
                    SentToUser  = user.Name
                });
            }
        }
コード例 #3
0
        public ActionResult SendSMS()
        {

            //  ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            string username = "******";
            string password = "******";
            string msgsender = "NCrypted Technologies";
            string destinationaddr = "+918866658130";
            string message = "Hello Uttam From Jignesh";

            ViaNettSMS s = new ViaNettSMS(username, password);
            ViaNettSMS.Result result;
            try
            {
                result = s.sendSMS(msgsender, destinationaddr, message);

                if (result.Success)
                {
                    //response.Write("Message successfully sent");
                    ViewBag.Message = "Message successfully sent.";
                }
                else
                {
                    //response.Write("Received error:" + result.ErrorCode + " " + result.ErrorMessage);
                    ViewBag.Message = "Received error:" + result.ErrorCode + " " + result.ErrorMessage;
                }
            }
            catch (System.Net.WebException ex)
            {
                //Error occurred while connecting to server.
                //response.Write(ex.Message);
                ViewBag.Message = ex.Message;
            }

            return View();
        }