diff --git a/src/Postmark.Tests/ClientSendingTests.cs b/src/Postmark.Tests/ClientSendingTests.cs index 05cc7ae..cda08da 100644 --- a/src/Postmark.Tests/ClientSendingTests.cs +++ b/src/Postmark.Tests/ClientSendingTests.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using PostmarkDotNet.Exceptions; namespace Postmark.Tests { @@ -89,6 +90,25 @@ public async void Client_CanSendAPostmarkMessageWithEmptyTrackLinks() Assert.NotEqual(Guid.Empty, result.MessageID); } + [Fact] + public async void UnknownMessageStream_ThrowsException() + { + var inboundAddress = (await _client.GetServerAsync()).InboundAddress; + var message = ConstructMessage(inboundAddress, 0, null); + message.MessageStream = "outbound"; + + // Testing the default transactional stream + var result = await _client.SendMessageAsync(message); + Assert.Equal(PostmarkStatus.Success, result.Status); + Assert.Equal(0, result.ErrorCode); + Assert.NotEqual(Guid.Empty, result.MessageID); + + // Testing an invalid non-existing stream + message.MessageStream = "unknown-stream"; + + await Assert.ThrowsAsync(() => _client.SendMessageAsync(message)); + } + private PostmarkMessage ConstructMessage(string inboundAddress, int number = 0, LinkTrackingOptions? trackLinks = LinkTrackingOptions.HtmlAndText) { var message = new PostmarkMessage() diff --git a/src/Postmark/Model/PostmarkMessage.cs b/src/Postmark/Model/PostmarkMessage.cs index 1033963..0405a22 100644 --- a/src/Postmark/Model/PostmarkMessage.cs +++ b/src/Postmark/Model/PostmarkMessage.cs @@ -22,9 +22,9 @@ public PostmarkMessage() /// The HTML Body to be used for the message, this may be null if TextBody is set. /// A collection of additional mail headers to send with the message. (optional) /// A dictionary of metadata to send with the message. (optional) + /// The message stream used to send this message. If not provided, the default transactional stream "outbound" will be used. (optional) public PostmarkMessage(string from, string to, string subject, string textBody, string htmlBody, - HeaderCollection headers = null, - IDictionary metadata = null): base() + HeaderCollection headers = null, IDictionary metadata = null, string messageStream = null) : base() { From = from; To = to; @@ -33,6 +33,7 @@ public PostmarkMessage(string from, string to, string subject, string textBody, HtmlBody = htmlBody; Headers = headers ?? new HeaderCollection(); Metadata = metadata; + MessageStream = messageStream; } /// diff --git a/src/Postmark/Model/PostmarkMessageBase.cs b/src/Postmark/Model/PostmarkMessageBase.cs index f408544..c0fd8cf 100644 --- a/src/Postmark/Model/PostmarkMessageBase.cs +++ b/src/Postmark/Model/PostmarkMessageBase.cs @@ -19,6 +19,11 @@ public PostmarkMessageBase() TrackLinks = LinkTrackingOptions.None; } + /// + /// The message stream used to send this message. + /// + public string MessageStream { get; set; } + /// /// The sender's email address. /// diff --git a/src/Postmark/PostmarkClient.cs b/src/Postmark/PostmarkClient.cs index 449f354..0d02c5e 100644 --- a/src/Postmark/PostmarkClient.cs +++ b/src/Postmark/PostmarkClient.cs @@ -863,10 +863,11 @@ public async Task SendEmailWithTemplateAsync(string templat bool? trackOpens = null, IDictionary headers = null, IDictionary metadata = null, + string messageStream = null, params PostmarkMessageAttachment[] attachments) { return await InternalSendEmailWithTemplateAsync(templateAlias, templateModel, to, from, inlineCss, cc, - bcc, replyTo, trackOpens, headers, metadata, attachments); + bcc, replyTo, trackOpens, headers, metadata, messageStream, attachments); } public async Task SendEmailWithTemplateAsync(long templateId, T templateModel, @@ -876,10 +877,11 @@ public async Task SendEmailWithTemplateAsync(long templateI bool? trackOpens = null, IDictionary headers = null, IDictionary metadata = null, + string messageStream = null, params PostmarkMessageAttachment[] attachments) { return await InternalSendEmailWithTemplateAsync(templateId, templateModel, to, from, inlineCss, cc, - bcc, replyTo, trackOpens, headers, metadata, attachments); + bcc, replyTo, trackOpens, headers, metadata, messageStream, attachments); } private async Task InternalSendEmailWithTemplateAsync(object templateReference, T templateModel, @@ -889,6 +891,7 @@ private async Task InternalSendEmailWithTemplateAsync(objec bool? trackOpens = null, IDictionary headers = null, IDictionary metadata = null, + string messageStream = null, params PostmarkMessageAttachment[] attachments) { @@ -902,6 +905,7 @@ private async Task InternalSendEmailWithTemplateAsync(objec email.TemplateAlias = (string)templateReference; } email.TemplateModel = templateModel; + email.MessageStream = messageStream; email.To = to; email.From = from; if (inlineCss.HasValue) diff --git a/src/Postmark/PostmarkClientExtensions.cs b/src/Postmark/PostmarkClientExtensions.cs index 435fe0a..09775cb 100644 --- a/src/Postmark/PostmarkClientExtensions.cs +++ b/src/Postmark/PostmarkClientExtensions.cs @@ -10,7 +10,6 @@ namespace PostmarkDotNet /// public static class PostmarkClientExtensions { - /// /// Sends a message through the Postmark API. /// All email addresses must be valid, and the sender must be @@ -25,14 +24,16 @@ public static class PostmarkClientExtensions /// The Plain Text Body to be used for the message, this may be null if HtmlBody is set. /// The HTML Body to be used for the message, this may be null if TextBody is set. /// A collection of additional mail headers to send with the message. + /// The message stream used to send this message. /// A with details about the transaction. public static async Task SendMessageAsync(this PostmarkClient client, string from, string to, string subject, string textBody, string htmlBody, - IDictionary headers = null, - IDictionary metadata = null) + IDictionary headers = null, + IDictionary metadata = null, + string messageStream = null) { - var message = new PostmarkMessage(from, to, subject, textBody, htmlBody, - new HeaderCollection(headers), metadata); + var message = new PostmarkMessage(from, to, subject, textBody, htmlBody, + new HeaderCollection(headers), metadata, messageStream); return await client.SendMessageAsync(message); }