Error when trying to send HTML email on event onActivateUser Background:

I'm working on a site that has frontend registration with some custom fields. The client would like to have a notification email whenever someone activates their account, containing the info on that user (so name, email and the custom fields). 



Issue at hand:

For some reason, I'm getting the following error when I try to send an HTML email on the 'onActivateUser': 


  Unable to find the template “_emails/customer-service-notification”.


If however I try to send a plain text email, it all goes without problem. 

I'd prefer to send out an HTML email so I'd like to resolve this. 



What I already tried:


Triggering the service function in another way (via custom controller action) sends the html email just fine
Sending the mail by just setting the content as string in the function works just fine




Code:

Main plugin file - init function

craft()-&gt;on('users.onActivateUser', function (Event $event){
    $user = $event-&gt;params['user'];
    craft()-&gt;plugin_customerServiceNotification-&gt;sendNotificationMail($user);
});


customerServiceNotification

public function sendNotificationMail(UserModel $user){
    $mailer = craft()-&gt;email;
    $mailToBeSent = new EmailModel();

    $mailToBeSent-&gt;subject = Craft::t('Nieuwe gebruiker geregistreerd');
    $mailToBeSent-&gt;fromName = 'xyz';
    $mailToBeSent-&gt;sender = 'noreply@xyz.be';

    $mailToBeSent-&gt;toEmail = 'xyz@xyz.be';

    $content = craft()-&gt;templates-&gt;render(
        '_emails/customer-service-notification',
        [
            'userInfo' =&gt; [
                'email' =&gt; $user-&gt;email,
                'name' =&gt; $user-&gt;fullName,
            ],
        ]
    );
    $mailToBeSent-&gt;htmlBody = $content;

    $mailer-&gt;sendEmail($mailToBeSent);
}


Folder structure:
Changing sendNotificationEmail() to this should fix it for you:

public function sendNotificationMail(UserModel $user) {
    $mailer = craft()-&gt;email;
    $mailToBeSent = new EmailModel();

    $mailToBeSent-&gt;subject = Craft::t('Nieuwe gebruiker geregistreerd');
    $mailToBeSent-&gt;fromName = 'xyz';
    $mailToBeSent-&gt;sender = 'noreply@xyz.be';

    $mailToBeSent-&gt;toEmail = 'xyz@xyz.be';

    $originalTemplateMode = craft()-&gt;templates-&gt;getTemplateMode();
    craft()-&gt;template-&gt;setTemplateMode(TemplateMode::Site);

    $content = craft()-&gt;templates-&gt;render(
        '_emails/customer-service-notification',
        [
            'userInfo' =&gt; [
                'email' =&gt; $user-&gt;email,
                'name' =&gt; $user-&gt;fullName,
            ],
        ]
    );

    $mailToBeSent-&gt;htmlBody = $content;
    $mailer-&gt;sendEmail($mailToBeSent);

    craft()-&gt;templates-&gt;setTemplateMode($originalTemplateMode);
}