diff --git a/src/Postmark/PostmarkClient.php b/src/Postmark/PostmarkClient.php index 48b713b0..50ac09ad 100644 --- a/src/Postmark/PostmarkClient.php +++ b/src/Postmark/PostmarkClient.php @@ -40,11 +40,12 @@ function __construct($serverToken, $timeout = 30) { * @param array $attachments An array of PostmarkAttachment objects. * @param string $trackLinks Can be any of "None", "HtmlAndText", "HtmlOnly", "TextOnly" to enable link tracking. * @param array $metadata Add metadata to the message. The metadata is an associative array, and values will be evaluated as strings by Postmark. + * @param array $messageStream The message stream used to send this message. If not provided, the default transactional stream "outbound" will be used. * @return DynamicResponseModel */ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL, $tag = NULL, $trackOpens = true, $replyTo = NULL, $cc = NULL, $bcc = NULL, - $headers = NULL, $attachments = NULL, $trackLinks = NULL, $metadata = NULL) { + $headers = NULL, $attachments = NULL, $trackLinks = NULL, $metadata = NULL, $messageStream = NULL) { $body = array(); $body['From'] = $from; @@ -60,6 +61,7 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL, $body['TrackOpens'] = $trackOpens; $body['Attachments'] = $attachments; $body['Metadata'] = $metadata; + $body['MessageStream'] = $messageStream; // Since this parameter can override a per-server setting // we have to check whether it was actually set. @@ -88,12 +90,13 @@ function sendEmail($from, $to, $subject, $htmlBody = NULL, $textBody = NULL, * @param array $attachments An array of PostmarkAttachment objects. * @param string $trackLinks Can be any of "None", "HtmlAndText", "HtmlOnly", "TextOnly" to enable link tracking. * @param array $metadata Add metadata to the message. The metadata is an associative array , and values will be evaluated as strings by Postmark. + * @param array $messageStream The message stream used to send this message. If not provided, the default transactional stream "outbound" will be used. * @return DynamicResponseModel */ function sendEmailWithTemplate($from, $to, $templateIdOrAlias, $templateModel, $inlineCss = true, $tag = NULL, $trackOpens = true, $replyTo = NULL, $cc = NULL, $bcc = NULL, $headers = NULL, $attachments = NULL, - $trackLinks = NULL, $metadata = NULL) { + $trackLinks = NULL, $metadata = NULL, $messageStream = NULL) { $body = array(); $body['From'] = $from; @@ -108,6 +111,7 @@ function sendEmailWithTemplate($from, $to, $templateIdOrAlias, $templateModel, $ $body['TemplateModel'] = $templateModel; $body['InlineCss'] = $inlineCss; $body['Metadata'] = $metadata; + $body['MessageStream'] = $messageStream; // Since this parameter can override a per-server setting diff --git a/tests/PostmarkClientEmailTest.php b/tests/PostmarkClientEmailTest.php index e361f958..cddce234 100644 --- a/tests/PostmarkClientEmailTest.php +++ b/tests/PostmarkClientEmailTest.php @@ -8,6 +8,7 @@ use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; use Postmark\Models\PostmarkAttachment; +use Postmark\Models\PostmarkException; use Postmark\PostmarkClient; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; @@ -31,6 +32,36 @@ function testClientCanSendBasicMessage() { $this->assertNotEmpty($response, 'The client could not send a basic message.'); } + function testClientCanSetMessageStream() { + $tk = parent::$testKeys; + + $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT); + + $currentTime = date("c"); + + //Sending with a valid stream + $response = $client->sendEmail($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS, + $tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, + "Hello from the PHP Postmark Client Tests! ($currentTime)", + 'Hi there!', + 'This is a text body for a test email via the default stream.', NULL, true, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, 'outbound'); + $this->assertNotEmpty($response, 'The client could not send message to the default stream.'); + + // Sending with an invalid stream + try { + $response = $client->sendEmail($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS, + $tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, + "Hello from the PHP Postmark Client Tests! ($currentTime)", + 'Hi there!', + 'This is a text body for a test email.', NULL, true, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, 'unknown-stream'); + } catch(PostmarkException $ex){ + $this->assertEquals(422, $ex->httpStatusCode); + $this->assertEquals("The 'MessageStream' provided does not exist on this server.", $ex->message); + } + } + function testClientCanSendMessageWithRawAttachment() { $tk = parent::$testKeys;