/// <summary> /// send the text /// </summary> /// <param name="sms"></param> /// <returns></returns> public bool Send(Sms sms) { if (string.IsNullOrEmpty(sms.Message)) { throw new Exception("Message property cannot be null"); } if (sms.Numbers == null) { throw new Exception("Numbers property cannot be null"); } if (sms.Numbers.Count == 0) { throw new Exception("Numbers property cannot be empty"); } if (string.IsNullOrEmpty(sms.Numbers[0])) { throw new Exception("Must have a valid number"); } var postUrl = ConfigurationManager.AppSettings["TXT_LOCAL_URL"]; if (string.IsNullOrEmpty(postUrl)) { postUrl = @"http://www.txtlocal.com/sendsmspost.php"; } var username = ConfigurationManager.AppSettings["TXT_LOCAL_USERNAME"]; if (string.IsNullOrEmpty(username)) { username = @"*****@*****.**"; } var password = ConfigurationManager.AppSettings["TXT_LOCAL_PASSWORD"]; if (string.IsNullOrEmpty(password)) { password = @"I11uminate"; } var numbersToSend = string.Join(",", sms.Numbers); //use restsharp to talk to the txtlocal rest service var client = new RestClient { BaseUrl = postUrl }; var request = new RestRequest(Method.POST); request.AddParameter("uname", username); request.AddParameter("pword", password); request.AddParameter("from", sms.From); request.AddParameter("message", sms.Message); request.AddParameter("selectednums", numbersToSend); //execute the post request to txtlocal - should send the sms var response = client.Execute(request); return response.ResponseStatus == ResponseStatus.Completed; }
public bool Dispatch(Notification notification,IDocumentStore store) { var phoneNumbers = new List<string>(); foreach (var users in notification.NotificationRecipients.Select(r=>r.Users)) { phoneNumbers.AddRange(users.Where(u=>!string.IsNullOrEmpty(u.MobilePhoneNumber)).Select(u => u.MobilePhoneNumber)); } var message = notification.Body.Length >= 140 ? notification.Body.Substring(0, 140) : notification.Body; var sms = new Sms { From = "Illuminate", Message = message, Numbers = phoneNumbers }; bool sent=false; try { sent=_smsSender.Send(sms); } catch (Exception ex) { _log.Error(string.Format("Problem sending SMS"),ex); } if (sent) { using (var session = store.OpenSession()) { sms.Sent = true; sms.SentOn = DateTime.Now; session.Store(sms); session.SaveChanges(); } _log.Info(string.Format("succesfully sent sms to provider")); return true; } _log.Error(string.Format("problem submitting sms to provider")); return false; }
public static void TestSms() { var nums = new List<String> {"447539363671"}; var sms = new Sms { From = "illuminate", Message = "Hi There!", Numbers = nums }; new TxtLocalSmsSender().Send(sms); }