diff --git a/src/Message/MessageBuilder.php b/src/Message/MessageBuilder.php index 5182202..8f7522a 100644 --- a/src/Message/MessageBuilder.php +++ b/src/Message/MessageBuilder.php @@ -278,6 +278,20 @@ class MessageBuilder return $this; } + public function addStringAttachment(string $attachmentContent, string $attachmentName = null): self + { + if (!isset($this->message['attachment'])) { + $this->message['attachment'] = []; + } + + $this->message['attachment'][] = [ + 'fileContent' => $attachmentContent, + 'filename' => $attachmentName, + ]; + + return $this; + } + public function addInlineImage(string $inlineImagePath, string $inlineImageName = null): self { if (!isset($this->message['inline'])) { diff --git a/tests/Message/MessageBuilderTest.php b/tests/Message/MessageBuilderTest.php index 5e32ade..4ac44ee 100644 --- a/tests/Message/MessageBuilderTest.php +++ b/tests/Message/MessageBuilderTest.php @@ -161,6 +161,26 @@ class MessageBuilderTest extends MailgunTestCase ); } + public function testAddStringAttachment() + { + $this->messageBuilder->addStringAttachment('12345'); + $this->messageBuilder->addStringAttachment('test'); + $message = $this->messageBuilder->getMessage(); + $this->assertEquals( + [ + [ + 'fileContent' => '12345', + 'filename' => null, + ], + [ + 'fileContent' => 'test', + 'filename' => null, + ], + ], + $message['attachment'] + ); + } + public function testAddInlineImages() { $this->messageBuilder->addInlineImage('@../TestAssets/mailgun_icon.png');