static void Main(string[] args) { (var clientId, var clientSecret) = IO.GetKeysFromUser(); var httpClient = new HttpClient(); var authService = new SendPulseAuthService(httpClient, clientId, clientSecret); var emailService = new SendPulseEmailService(authService, httpClient); var sendFrom = IO.GetFromEmailAddress(); var sendTo = IO.GetToEmailAddresses(); var message = new SendPulseSmtpRequestModel { Email = new SmtpRequestEmailModel { From = sendFrom, To = sendTo, Html = "<h1>Test Email</h1>", Text = "Test Email", Subject = "Test Email" } }; Console.WriteLine("Sending email..."); var response = emailService.SendAsync(message); response.ContinueWith(responseAsync => { if (responseAsync.IsFaulted) { Console.WriteLine("Error!"); Console.WriteLine(responseAsync.Exception); return; } Console.WriteLine("Sent."); var result = responseAsync.Result; Console.WriteLine("Response: " + (int)result.StatusCode + ", " + result.StatusCode.ToString()); var body = result.Content.ReadAsStringAsync().Result; Console.WriteLine(body); }); Console.ReadLine(); }
public async Task <HttpResponseMessage> SendAsync(SendPulseSmtpRequestModel request) { var settings = new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() }; var json = JsonConvert.SerializeObject(request, settings); var httpRequest = new HttpRequestMessage(new HttpMethod("POST"), $"{Config.SendPulseApiUrl}smtp/emails") { Content = new StringContent(json, Encoding.UTF8, "application/json") }; await SendPulseAuthService.AttachCredentialsToRequest(httpRequest); return(await HttpClient.SendAsync(httpRequest)); }
public async Task SendAsync( SmtpRequestEmailAddressModel[] to, SmtpRequestEmailAddressModel from, string subject, string htmlBody, string plaintextBody, Dictionary <string, string> attachments = null, Dictionary <string, string> attachmentsBinary = null) { var request = new SendPulseSmtpRequestModel { Email = new SmtpRequestEmailModel { Attachments = attachments, AttachmentsBinary = attachmentsBinary, From = from, Html = htmlBody, Subject = subject, Text = plaintextBody, To = to } }; await SendAsync(request); }