hooks setting in project php config file.'hooks' => [
'actions' => [
'item.create.messages' => function ($data) {
$container = Application::getInstance()->getContainer();
$mailService = new MailService($container);
$mailService->send([
'type' => 'html',
'subject' => "subject",
'body' => 'new message created'',
'data' => [],
'to' => [
[ 'name' => 'Gavin Luo', 'email' => '[email protected]' ]
],
]);
},
],
],
{
"error": {
"code": null,
"message": "Address in mailbox given [] does not comply with RFC 2822, 3.6.2.",
"class": "Swift_RfcComplianceException",
"file": "\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Mime\/Headers\/MailboxHeader.php",
"line": 345
}
}
Also send email when on public api request to create message item.
Address in mailbox given [] does not comply with RFC 2822, 3.6.2. error
Public role create permission has been setted and the message item can create normally, just email sending now working.
v8.2.0 tagged branch, manual build and install@bjgajjar I found the problem is that the send function setFrom is false.
Why we send false to setFrom and use default from from setting must have a Admin permission?
Can we change it to use a from key from data to set mail from and if it not exist, we use the default mail from and without admin permission?
Or is there an official recommended best practice for sending emails for extension?
reference commit https://github.com/directus/api/commit/ef40463a88ca8379188b596439da5bcfaadf5e9f
looks like https://github.com/symfony/mailer is great for me, maybe I can use it and wrapped as an extension.
@everyx - We really appreciate you taking the time to debug an issue. As you mentioned;
Can we change it to use a from key from data to set mail from and if it not exist, we use the default mail from and without admin permission?
It is already doing that. from is set with getFrom method. And the getFrom method is doing exactly the same which you have mentioned. Please check the code here
maybe I can use it and wrapped it as an extension.
Yeah. Please do it and feel free to send the PR also :)
Just close this issue and it's not a bug. :)