Exemplo n.º 1
0
        public async Task <bool> SendSingleEmailAsync(SendSingleEmailRequestModel model)
        {
            string        json          = JsonConvert.SerializeObject(model);
            StringContent stringContent = new StringContent(json, Encoding.Default, "application/json");


            var result = await _client.PostAsync("email/public/v1/singleEmail/send?hapikey=" + APIKey, stringContent);

            var jsonResponse = await result.Content.ReadAsStringAsync();


            if (result.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                var response = JsonConvert.DeserializeObject <BaseModel>(jsonResponse);
                if (response?.ValidationResults?.Where(v => v.isValid == false).Count() > 0)
                {
                    throw new ValidationException(response.ValidationResults.Where(v => v.isValid == false).First().message);
                }
                else if (response != null && response.Message != null)
                {
                    throw new Exception(response.Message);
                }
                else
                {
                    throw new Exception("Unkown Error");
                }
            }
        }
Exemplo n.º 2
0
 public bool SendSingleEmail(SendSingleEmailRequestModel model) => SendSingleEmailAsync(model).GetAwaiter().GetResult();