/// <summary> /// Sends a message through the Postmark API. /// All email addresses must be valid, and the sender must be /// a valid sender signature according to Postmark. To obtain a valid /// sender signature, log in to Postmark and navigate to: /// http://postmarkapp.com/signatures. /// </summary> /// <param name="from">An email address for a sender.</param> /// <param name="to">An email address for a recipient.</param> /// <param name="subject">The message subject line.</param> /// <param name="body">The message body.</param> /// <param name="headers">A collection of additional mail headers to send with the message.</param> /// <returns>A <see cref = "PostmarkResponse" /> with details about the transaction.</returns> public static async Task <PostmarkResponse> SendMessageAsync(this PostmarkClient client, string from, string to, string subject, string body, IDictionary <string, string> headers = null) { var message = new PostmarkMessage(from, to, subject, body, headers); return(await client.SendMessageAsync(message)); }
public OutboundMessagePostmarkResponse SendPostmarkMessage(OutboundMessageRequest messageRequest) { if (messageRequest == null) { throw new ArgumentNullException(nameof(messageRequest)); } var postmarkMessage = Mapper.Map <OutboundMessageRequest, PostmarkMessage>(messageRequest); var postmarkClient = new PostmarkDotNet.PostmarkClient(_serverToken); var postmarkResponse = new PostmarkResponse(); var task = Task.Run(async() => { postmarkResponse = await postmarkClient.SendMessageAsync(postmarkMessage); }); try { task.Wait(); } catch (AggregateException ae) { var innerException = ae.InnerExceptions.FirstOrDefault(); throw new CommunicationException("External service exception occured on SendPostmarkMessage.", innerException); } return(Mapper.Map <PostmarkResponse, OutboundMessagePostmarkResponse>(postmarkResponse)); }
/// <summary> /// Sends a message through the Postmark API. /// All email addresses must be valid, and the sender must be /// a valid sender signature according to Postmark. To obtain a valid /// sender signature, log in to Postmark and navigate to: /// http://postmarkapp.com/signatures. /// </summary> /// <param name="client">The postmark client instance on which to do the send.</param> /// <param name="from">An email address for a sender.</param> /// <param name="to">An email address for a recipient.</param> /// <param name="subject">The message subject line.</param> /// <param name="textBody">The Plain Text Body to be used for the message, this may be null if HtmlBody is set.</param> /// <param name="htmlBody">The HTML Body to be used for the message, this may be null if TextBody is set.</param> /// <param name="headers">A collection of additional mail headers to send with the message.</param> /// <returns>A <see cref = "PostmarkResponse" /> with details about the transaction.</returns> public static async Task <PostmarkResponse> SendMessageAsync(this PostmarkClient client, string from, string to, string subject, string textBody, string htmlBody, IDictionary <string, string> headers = null, IDictionary <string, string> metadata = null) { var message = new PostmarkMessage(from, to, subject, textBody, htmlBody, new HeaderCollection(headers), metadata); return(await client.SendMessageAsync(message)); }
public async Task ClientCanSendMessage() { var client = new PostmarkClient(WRITE_TEST_SERVER_TOKEN); var response = await client .SendMessageAsync(WRITE_TEST_SENDER_EMAIL_ADDRESS, WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, "Testing the postmark client: " + DateTime.Now, "<b>This is only a test!</b>"); // This should successfully send. Assert.AreEqual(0, response.ErrorCode); Assert.AreEqual("OK", response.Message); }
/// <summary> /// Send a System.Net.MailMessage (transparently converts to the PostmarkMessage). /// </summary> /// <param name="client"></param> /// <param name="message"></param> /// <returns></returns> public static async Task <PostmarkResponse> SendMessageAsync (this PostmarkClient client, MailMessage message) { return(await client.SendMessageAsync(ConvertSystemMailMessage(message))); }