/// <summary> /// Sends transactional emails using send API v3.1 /// </summary> public async Task <TransactionalEmailResponse> SendTransactionalEmailsAsync(IEnumerable <TransactionalEmail> transactionalEmails, bool isSandboxMode = false, bool advanceErrorHandling = true) { if (transactionalEmails.Count() > SendV31.MaxEmailsPerBatch || !transactionalEmails.Any()) { throw new MailjetClientConfigurationException($"Send Emails API v3.1 allows to send not more than {SendV31.MaxEmailsPerBatch} emails per call"); } var request = new SendEmailRequest { Messages = transactionalEmails.ToList(), SandboxMode = isSandboxMode, AdvanceErrorHandling = advanceErrorHandling }; var clientRequest = new MailjetRequest { Resource = SendV31.Resource, Body = JObject.FromObject(request, Serializer) }; var clientResponse = await PostAsync(clientRequest) .ConfigureAwait(false); var result = clientResponse.Content.ToObject <TransactionalEmailResponse>(); return(result); }
public async Task <MailjetResponse> DeleteAsync(MailjetRequest request) { string url = request.BuildUrl(); var responseMessage = await _httpClient.DeleteAsync(url).ConfigureAwait(false); JObject content = await GetContent(responseMessage).ConfigureAwait(false); return(new MailjetResponse(responseMessage.IsSuccessStatusCode, (int)responseMessage.StatusCode, content)); }
public async Task <MailjetResponse> GetAsync(MailjetRequest request) { string url = BuildUrl(request); var responseMessage = await _httpClient.GetAsync(url); JObject content = await GetContent(responseMessage); return(new MailjetResponse(responseMessage.IsSuccessStatusCode, (int)responseMessage.StatusCode, content)); }
public async Task <MailjetResponse> PostAsync(MailjetRequest request) { string url = request.BuildUrl(); var output = request.Body.ToString(Formatting.None); HttpContent contentPost = new StringContent(output, Encoding.UTF8, MailjetConstants.JsonMediaType); var responseMessage = await _httpClient.PostAsync(url, contentPost).ConfigureAwait(false); JObject content = await GetContent(responseMessage).ConfigureAwait(false); return(new MailjetResponse(responseMessage.IsSuccessStatusCode, (int)responseMessage.StatusCode, content)); }
public async Task <MailjetResponse> PutAsync(MailjetRequest request) { string url = BuildUrl(request); var output = request.Body.ToString(Formatting.None); HttpContent contentPut = new StringContent(output, Encoding.UTF8, JsonMediaType); var responseMessage = await _httpClient.PutAsync(url, contentPut); JObject content = await GetContent(responseMessage); MailjetResponse mailjetResponse = new MailjetResponse(responseMessage.IsSuccessStatusCode, (int)responseMessage.StatusCode, content); return(mailjetResponse); }
private string BuildUrl(MailjetRequest request) { return(UrlHelper.CombineUrl(GetApiVersionPath(), request.BuildUrl())); }