diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2016-12-09 22:21:34 -0800 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2016-12-09 22:21:34 -0800 |
commit | c8cb64deec10ac760e99f97969c7ccefda846e57 (patch) | |
tree | ecb8ea83d7187ae4bd1148a6d379798d5afca346 /src | |
parent | 85ee9ec77ecaa924904a8800eced145565b70073 (diff) | |
download | sendgrid-csharp-c8cb64deec10ac760e99f97969c7ccefda846e57.zip sendgrid-csharp-c8cb64deec10ac760e99f97969c7ccefda846e57.tar.gz sendgrid-csharp-c8cb64deec10ac760e99f97969c7ccefda846e57.tar.bz2 |
Refinements to SendEmailAsync
Diffstat (limited to 'src')
-rw-r--r-- | src/SendGrid/Client.cs | 12 | ||||
-rw-r--r-- | src/SendGrid/Helpers/Mail/Mail.cs | 13 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/SendGrid/Client.cs b/src/SendGrid/Client.cs index 7beeeb2..4eabcea 100644 --- a/src/SendGrid/Client.cs +++ b/src/SendGrid/Client.cs @@ -58,6 +58,12 @@ namespace SendGrid } } + public static class MimeType + { + public static readonly string HTML = "text/html"; + public static readonly string Text = "text/plain"; + } + public class Client { public string Host; @@ -66,7 +72,7 @@ namespace SendGrid public string UrlPath; public string MediaType; public IWebProxy WebProxy; - public enum Methods { DELETE, GET, PATCH, POST, PUT } + public enum Method { DELETE, GET, PATCH, POST, PUT } public Mail Mail { get; set; } /// <summary> @@ -228,7 +234,7 @@ namespace SendGrid /// <param name="client">Client object ready for communication with API</param> /// <param name="request">The parameters for the API call</param> /// <returns>Response object</returns> - public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMessage request) + public async Task<Response> MakeRequest(HttpClient client, HttpRequestMessage request) { HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); return new Response(response.StatusCode, response.Content, response.Headers); @@ -241,7 +247,7 @@ namespace SendGrid /// <param name="requestBody">JSON formatted string</param> /// <param name="queryParams">JSON formatted query paramaters</param> /// <returns>Response object</returns> - public async Task<Response> RequestAsync(Client.Methods method, + public async Task<Response> RequestAsync(Client.Method method, string requestBody = null, Dictionary<string, string> requestHeaders = null, string queryParams = null, diff --git a/src/SendGrid/Helpers/Mail/Mail.cs b/src/SendGrid/Helpers/Mail/Mail.cs index f505ec0..d9ad829 100644 --- a/src/SendGrid/Helpers/Mail/Mail.cs +++ b/src/SendGrid/Helpers/Mail/Mail.cs @@ -14,6 +14,13 @@ namespace SendGrid.Helpers.Mail _client = client; } + public async Task<Response> SendEmailAsync(SendGridMessage msg) + { + return await _client.RequestAsync(Client.Method.POST, + msg.Get(), + urlPath: "mail/send").ConfigureAwait(false); + } + public async Task<Response> SendSingleEmailAsync(MailAddress from, MailAddress to, string subject, @@ -27,14 +34,14 @@ namespace SendGrid.Helpers.Mail } msg.From = from; msg.Subject = subject; - var text = new Content("text/plain", contentText); + var text = new Content(MimeType.Text, contentText); msg.AddContent(text); - var html = new Content("text/html", contentHTML); + var html = new Content(MimeType.HTML, contentHTML); msg.AddContent(html); var p = new Personalization(); p.AddTo(to); msg.AddPersonalization(p); - return await _client.RequestAsync(Client.Methods.POST, msg.Get(),urlPath: "mail/send").ConfigureAwait(false); + return await SendEmailAsync(msg).ConfigureAwait(false); } } } |