1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/Email/EmailMailable.php

101 lines
2.6 KiB
PHP
Raw Normal View History

2023-01-15 04:44:23 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2023-01-15 04:44:23 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Email;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Headers;
class EmailMailable extends Mailable
{
/**
* Create a new message instance.
*
* @return void
*/
2023-02-16 02:36:09 +01:00
public function __construct(public EmailObject $email_object)
{
}
2023-01-15 04:44:23 +01:00
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: $this->email_object->subject,
tags: [$this->email_object->company_key],
replyTo: $this->email_object->reply_to,
from: $this->email_object->from,
to: $this->email_object->to,
bcc: $this->email_object->bcc
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
2023-01-15 11:20:16 +01:00
view: $this->email_object->html_template,
2023-01-15 04:44:23 +01:00
text: $this->email_object->text_template,
with: [
2023-01-15 11:16:10 +01:00
'text_body' => strip_tags($this->email_object->body), //@todo this is a bit hacky here.
2023-01-15 04:44:23 +01:00
'body' => $this->email_object->body,
'settings' => $this->email_object->settings,
'whitelabel' => $this->email_object->whitelabel,
'logo' => $this->email_object->logo,
'signature' => $this->email_object->signature,
'company' => $this->email_object->company,
'greeting' => ''
]
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
$attachments = [];
2023-02-16 02:36:09 +01:00
foreach ($this->email_object->attachments as $file) {
2023-01-15 04:44:23 +01:00
$attachments[] = Attachment::fromData(fn () => base64_decode($file['file']), $file['name']);
}
return $attachments;
}
/**
* Get the message headers.
*
* @return \Illuminate\Mail\Mailables\Headers
*/
public function headers()
{
return new Headers(
messageId: null,
references: [],
text: $this->email_object->headers,
);
}
}