private async Task <MmsResponse> SendMms(string address, string message, List <Windows.Storage.StorageFile> attachments, MmsPriority priority = MmsPriority.Normal) { Argument.ExpectNotNullOrWhiteSpace(() => message); Argument.ExpectNotNullOrWhiteSpace(() => address); string timeStampStr = "----------------------------" + DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture); string textContent = GetTextContent(timeStampStr, address, message); HttpContent content; if (attachments != null && attachments.Count > 0) { byte[] bytes = await EncodeBinaryContent(attachments, textContent, timeStampStr); content = new ByteArrayContent(bytes); } else { textContent = textContent + "--" + timeStampStr + "--\r\n"; content = new StringContent(textContent); } content.Headers.ContentType = CreateContentTypeHeader(timeStampStr); var requestUri = new Uri(Settings.EndPoint, SendRelativeUrl); string strResponse = await SendContentRequest(HttpMethod.Post, requestUri.ToString(), content); return(MmsResponse.Parse(strResponse)); }
/// <summary> /// This method will be called when user clicks on send mms button /// </summary> /// <param name="sender">object, that caused this event</param> /// <param name="e">Event that invoked this function</param> protected void SendButton_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(phoneListTextBox.Text)) { this.DrawPanelForFailure(sendMMSPanel, "Specify phone number"); return; } string[] phoneNumbers = phoneListTextBox.Text.Split(','); List <string> phoneNumbersList = new List <string>(phoneNumbers.Length); phoneNumbersList.AddRange(phoneNumbers); MmsResponse resp = this.requestFactory.SendMms(phoneNumbersList, subjectLabel.Text.Trim(), this.mmsAttachments); msgIdLabel.Text = resp.MessageId; this.DrawPanelForSuccess(sendMMSPanel, resp.MessageId); } catch (ArgumentException ex) { this.DrawPanelForFailure(sendMMSPanel, ex.ToString()); } catch (InvalidResponseException ex) { this.DrawPanelForFailure(sendMMSPanel, ex.Body); } catch (Exception ex) { this.DrawPanelForFailure(sendMMSPanel, ex.ToString()); } }
private async void btnSendMMS_Click(object sender, RoutedEventArgs e) { statusProgress.Visibility = Visibility.Visible; txtResult.Visibility = Visibility.Collapsed; btnSendMMS.IsEnabled = false; clientId = "your_att_app_key"; clientSecret = "your_att_secret_key"; uriString = "https://api.att.com"; List <string> phoneNumbers = txtPhone.Text.Split(';').ToList <string>(); MmsService mmsService = new MmsService(new AttServiceSettings(clientId, clientSecret, new Uri(uriString))); List <ContentInfo> attachments = new List <ContentInfo>(); attachments.Add(_mmsContent); MmsResponse mmsResponse = await mmsService.SendMms(phoneNumbers, txtMessage.Text, attachments); if (null != mmsResponse) { txtResult.Visibility = Visibility.Visible; txtResult.Text = "Message has been sent"; } statusProgress.Visibility = Visibility.Collapsed; btnSendMMS.IsEnabled = true; }
/// <summary> /// Sends MMS message to multiple recipients /// </summary> /// <param name="mms">MMS message to be sent.</param> /// <returns>Returns Task as a result of asynchronous operation. task result is <see cref="MmsMessage"/> sent MMS.</returns> /// <exception cref="System.ArgumentNullException">mms is null.</exception> public async Task <MmsMessage> Send(MmsMessage mms) { Argument.ExpectNotNull(() => mms); MmsResponse taskResp = await _mmsServiceWrapper.SendMms(mms.PhoneNumbers.Select(p => p.Number).ToList(), mms.Body, mms.Attachments); mms.MessageId = taskResp.Id; return(mms); }