Skip to content

Commit

Permalink
Merge pull request #67 from wildbit/task/add-message-stream-to-sendin…
Browse files Browse the repository at this point in the history
…g-api

Task/add message stream to sending api
  • Loading branch information
vladsandu authored Mar 24, 2020
2 parents eb205b9 + 4946abb commit 9ec6c1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Postmark/PostmarkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/PostmarkClientEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)",
'<b>Hi there!</b>',
'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)",
'<b>Hi there!</b>',
'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;

Expand Down

0 comments on commit 9ec6c1b

Please sign in to comment.