{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/6324","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/6324/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/6324/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/6324/events","html_url":"https://github.com/cakephp/cakephp/pull/6324","id":67937741,"number":6324,"title":"RFC - Mailer","user":{"login":"jadb","id":33527,"avatar_url":"https://avatars.githubusercontent.com/u/33527?v=3","gravatar_id":"","url":"https://api.github.com/users/jadb","html_url":"https://github.com/jadb","followers_url":"https://api.github.com/users/jadb/followers","following_url":"https://api.github.com/users/jadb/following{/other_user}","gists_url":"https://api.github.com/users/jadb/gists{/gist_id}","starred_url":"https://api.github.com/users/jadb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jadb/subscriptions","organizations_url":"https://api.github.com/users/jadb/orgs","repos_url":"https://api.github.com/users/jadb/repos","events_url":"https://api.github.com/users/jadb/events{/privacy}","received_events_url":"https://api.github.com/users/jadb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/Enhancement","name":"Enhancement","color":"bfe5bf"}],"state":"open","locked":false,"assignee":{"login":"jadb","id":33527,"avatar_url":"https://avatars.githubusercontent.com/u/33527?v=3","gravatar_id":"","url":"https://api.github.com/users/jadb","html_url":"https://github.com/jadb","followers_url":"https://api.github.com/users/jadb/followers","following_url":"https://api.github.com/users/jadb/following{/other_user}","gists_url":"https://api.github.com/users/jadb/gists{/gist_id}","starred_url":"https://api.github.com/users/jadb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jadb/subscriptions","organizations_url":"https://api.github.com/users/jadb/orgs","repos_url":"https://api.github.com/users/jadb/repos","events_url":"https://api.github.com/users/jadb/events{/privacy}","received_events_url":"https://api.github.com/users/jadb/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/31","html_url":"https://github.com/cakephp/cakephp/milestones/3.1.0","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/31/labels","id":919718,"number":31,"title":"3.1.0","description":"Backwards compatible with 3.0.x.\r\n\r\nSee the [Roadmap](https://github.com/cakephp/cakephp/wiki/3.1-Roadmap) for more information.","creator":{"login":"lorenzo","id":37621,"avatar_url":"https://avatars.githubusercontent.com/u/37621?v=3","gravatar_id":"","url":"https://api.github.com/users/lorenzo","html_url":"https://github.com/lorenzo","followers_url":"https://api.github.com/users/lorenzo/followers","following_url":"https://api.github.com/users/lorenzo/following{/other_user}","gists_url":"https://api.github.com/users/lorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/lorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lorenzo/subscriptions","organizations_url":"https://api.github.com/users/lorenzo/orgs","repos_url":"https://api.github.com/users/lorenzo/repos","events_url":"https://api.github.com/users/lorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/lorenzo/received_events","type":"User","site_admin":false},"open_issues":50,"closed_issues":64,"state":"open","created_at":"2015-01-02T15:38:07Z","updated_at":"2015-06-02T22:01:40Z","due_on":"2015-07-26T04:00:00Z","closed_at":null},"comments":21,"created_at":"2015-04-12T17:36:01Z","updated_at":"2015-06-03T11:36:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cakephp/cakephp/pulls/6324","html_url":"https://github.com/cakephp/cakephp/pull/6324","diff_url":"https://github.com/cakephp/cakephp/pull/6324.diff","patch_url":"https://github.com/cakephp/cakephp/pull/6324.patch"},"body":"This supersedes #6319 and as suggested by @markstory, adds some conventions borrowed from Rails' [ActionMailer](http://edgeguides.rubyonrails.org/action_mailer_basics.html).\r\n\r\n## TODO\r\n\r\n- [x] Move all email related classes out of `Cake\\Network\\Email` and into their own namespace. Agreed with @markstory and @lorenzo on `Cake\\Mailer`, with aliases for BC.\r\n- [x] Move transports into their own namespace at `Cake\\Mailer\\Transport` with aliases for BC.\r\n- [x] Create a new `Mailer` class that would make working with emails very similar to controllers (actions, templates, model-aware).\r\n- [ ] Create new bake command(s) to create mailer classes and/or templates.\r\n- [x] Update cakephp/app's `config/bootstrap.php` and `config/app.default.php`.\r\n\r\n## Usage\r\n\r\nFor documentation's sake and to better grasp the changes, here's a sample code of what would/should work when the work is finished.\r\n\r\n```\r\nbin/cake bake mailer user welcome,reset_password\r\n```\r\n\r\nwhich would generate the following:\r\n\r\n```\r\n- src/Mailer/UserMailer.php\r\n- src/Template/Layout/Email/html/user.ctp\r\n- src/Template/Layout/Email/text/user.ctp\r\n- src/Template/Email/html/User/welcome.ctp\r\n- src/Template/Email/html/User//reset_password.ctp\r\n- src/Template/Email/text/User/welcome.ctp\r\n- src/Template/Email/text/User/reset_password.ctp\r\n```\r\n\r\n`UserMailer` would look like this after some customizations:\r\n\r\n```php\r\n<?php\r\nnamespace App\\Mailer;\r\n\r\nuse ArrayObject;\r\nuse Cake\\Event\\Event;\r\nuse Cake\\Mailer\\Mailer;\r\nuse Cake\\ORM\\Entity;\r\n\r\nclass UserMailer extends Mailer\r\n{\r\n    public function welcome($user)\r\n    {\r\n        $this->subject = sprintf('Welcome %s', $user->name);\r\n        $this->to = $user->email;\r\n    }\r\n\r\n    public function resetPassword($user)\r\n    {\r\n        $this->subject = sprintf('Reset password');\r\n        $this->to = $user->email;\r\n        $this->set(['token' => $user->token]);\r\n    }\r\n\r\n    public function implementedEvents()\r\n    {\r\n        return [\r\n            'Model.afterSave' => 'onRegistration',\r\n        ];\r\n    }\r\n\r\n   public function onRegistration(Event $event, Entity $entity, ArrayObject $options)\r\n   {\r\n       if ($entity->isNew()) {\r\n            $this->send('welcome', [$entity]);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nAnd then from the controller (or any class using `MailerAwareTrait`):\r\n\r\n```php\r\n<?php\r\nnamespace App\\Controller;\r\n\r\nuse Cake\\Mailer\\MailerAwareTrait;\r\n\r\nclass UsersController extends AppController\r\n{\r\n    use MailerAwareTrait;\r\n\r\n    public function register()\r\n    {\r\n        ...\r\n        $this->getMailer('User')->send('welcome', [$user]);\r\n        ...\r\n    }\r\n}\r\n```\r\n\r\nor in a table using events:\r\n\r\n```php\r\n<?php\r\nnamespace App\\Model\\Table;\r\n\r\nuse App\\Mailer\\UserMailer;\r\nuse Cake\\ORM\\Table;\r\n\r\nclass UsersTable extends Table\r\n{\r\n    public function initialize(array $config = [])\r\n    {\r\n        ...\r\n        $this->eventManager->on(new UserMailer());\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/108322038","html_url":"https://github.com/cakephp/cakephp/pull/6324#issuecomment-108322038","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/6324","id":108322038,"user":{"login":"jadb","id":33527,"avatar_url":"https://avatars.githubusercontent.com/u/33527?v=3","gravatar_id":"","url":"https://api.github.com/users/jadb","html_url":"https://github.com/jadb","followers_url":"https://api.github.com/users/jadb/followers","following_url":"https://api.github.com/users/jadb/following{/other_user}","gists_url":"https://api.github.com/users/jadb/gists{/gist_id}","starred_url":"https://api.github.com/users/jadb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jadb/subscriptions","organizations_url":"https://api.github.com/users/jadb/orgs","repos_url":"https://api.github.com/users/jadb/repos","events_url":"https://api.github.com/users/jadb/events{/privacy}","received_events_url":"https://api.github.com/users/jadb/received_events","type":"User","site_admin":false},"created_at":"2015-06-03T11:36:55Z","updated_at":"2015-06-03T11:36:55Z","body":"@bcrowe there is! Thanks for pointing it out, totally slipped through the cracks! Will try finishing that today."}}