feat(EmailService): 添加邮件附件功能并更新单元测试

- 在 EmailService 类的 sendHtml 方法中添加了附件处理逻辑
- 更新了 EmailServiceTest 单元测试,增加了附件发送的测试用例
- 优化了测试用例的结构,提高了可读性和可维护性
This commit is contained in:
李东云
2025-03-03 09:57:04 +00:00
parent aaa4382ff2
commit 225bdedd23
2 changed files with 71 additions and 10 deletions

View File

@@ -130,6 +130,8 @@ class EmailService
string $html,
array $cc = [],
array $bcc = [],
array $attachmentPaths = [],
array $attachments = [],
int $priority = Email::PRIORITY_NORMAL
): bool {
$email = (new Email())
@@ -141,6 +143,22 @@ class EmailService
->subject($subject)
->html($html);
foreach ($attachmentPaths as $attachmentPath) {
if (is_string($attachmentPath)) {
$email = $email->attachFromPath($attachmentPath);
} else {
$email = $email->attachFromPath($attachmentPath['path'], $attachmentPath['name'] ?? null, $attachmentPath['mimeType'] ?? null);
}
}
foreach ($attachments as $attachment) {
if (is_string($attachment)) {
$email = $email->attach($attachment);
} else {
$email = $email->attach($attachment['content'], $attachment['name'] ?? null, $attachment['mimeType'] ?? null);
}
}
$this->mailer->send($email);
return true;