Creating reusable emails

I am looking at this https://book.cakephp.org/3.0/en/core-libraries/email.html#creating-reusable-emails

I follow the manual to create something like this:

<?php 
namespace App\Mailer;

use Cake\Mailer\Mailer;

class ArticleMailer extends Mailer
{
    public function implementedEvents()
    {
        return [
            'Model.afterSave' => 'onPost'
        ];
    }
    
    public function onPost(Event $event, EntityInterface $entity, ArrayObject $options)
    {
        if ($entity->isNew()) {
            $this->send('newarticle', [$entity]);
        }
    }
    
    public function newarticle($article)
    {
        $this
            ->setTo('info@gmail.com')
            ->setSubject(sprintf('New article posted %s', $article->name))
            ->setViewVars($article->toArray())
            ->setTemplate('newArticle');
    }
}

According to the manual this should work fine, but when adding a new article it does not get triggered? Am I missing some extra step I need to do that is not mentioned in the manual?

So I need to register the Mailer class on the model?

$articleMailer = new ArticleMailer();
$this->getEventManager()->on($ArticleMailer);

Now when I add an article it gets triggered but it is showing errors:

Argument 1 passed to App\Mailer\ArticleMailer::onPost() must be an instance of App\Mailer\Event, instance of Cake\Event\Event given

In your ArticleMailer implementation file, you need to use Cake\Event\Event, so that it knows the correct class in onPost(Event $event; as it stands, it expects to find that class in your existing namespace, and the thing that gets passed to it doesn’t match. You’ll also need to do similar things for EntityInterface and ArrayObject.