Skip to content

Commit 47690b6

Browse files
committed
Allow attachments.
1 parent 5ce8441 commit 47690b6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Queue/Task/EmailTask.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public function run(array $data, int $jobId): void {
177177
continue;
178178
}
179179

180+
// Special handling for attachments - pass the array directly
181+
if ($method === 'attachments') {
182+
$this->mailer->setAttachments($setting);
183+
184+
continue;
185+
}
186+
180187
call_user_func_array([$this->mailer, $setter], (array)$setting);
181188
}
182189

tests/TestCase/Queue/Task/EmailTaskTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,45 @@ public function testRunToolsEmailMessageClassString() {
246246
$this->Task->run($data, 0);
247247
}
248248

249+
/**
250+
* Test that attachments are properly handled when passed as an array
251+
*
252+
* @return void
253+
*/
254+
public function testRunWithAttachments() {
255+
$attachments = [
256+
'file1.txt' => [
257+
'file' => '/tmp/file1.txt',
258+
'mimetype' => 'text/plain',
259+
],
260+
'file2.pdf' => '/tmp/file2.pdf',
261+
];
262+
263+
$settings = [
264+
'from' => '[email protected]',
265+
'to' => '[email protected]',
266+
'subject' => 'Test with attachments',
267+
'attachments' => $attachments,
268+
];
269+
270+
$data = [
271+
'settings' => $settings,
272+
'content' => 'Email with attachments',
273+
];
274+
275+
$this->Task->run($data, 0);
276+
277+
$this->assertInstanceOf(Mailer::class, $this->Task->mailer);
278+
279+
$mailerAttachments = $this->Task->mailer->getMessage()->getAttachments();
280+
$this->assertCount(2, $mailerAttachments);
281+
$this->assertArrayHasKey('file1.txt', $mailerAttachments);
282+
$this->assertArrayHasKey('file2.pdf', $mailerAttachments);
283+
$this->assertSame('/tmp/file1.txt', $mailerAttachments['file1.txt']['file']);
284+
$this->assertSame('text/plain', $mailerAttachments['file1.txt']['mimetype']);
285+
$this->assertSame('/tmp/file2.pdf', $mailerAttachments['file2.pdf']);
286+
}
287+
249288
/**
250289
* Helper method for skipping tests that need a non Postgres connection.
251290
*

0 commit comments

Comments
 (0)