publicasync Task<IHttpActionResult> SendEmail(string message)
{
//Hosted web API REST Service base url string Baseurl = "http://services.domain.dev/";
SendMailModel mail = new SendMailModel();
mail.SendTo = "test@email.com";
mail.Body = message;
using (var client = new HttpClient())
{
//Passing service base url
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
//Define request data format
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var stringContent = new StringContent(JsonConvert.SerializeObject(mail), Encoding.UTF8, "application/json");
HttpResponseMessage Res = await client.PostAsync("api/Email/Send", stringContent);
//Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode)
return Ok(true);
return Ok(false);
}
}