Componette

Componette

download-cloud-line composer require adbros/nette-microsoft-mailer

Nette Microsoft Mailer

This library provides e-mail sending via Microsoft Graph API.


main workflow Licence Downloads this Month Downloads total Latest stable

How to install

composer require adbros/nette-microsoft-mailer

Azure setup

Register an application in Azure Portal

  1. Go to Azure Portal
  2. Go to Microsoft Entra ID -> App registrations
  3. Click on "New registration"
  4. Fill in the form:
    • Name: Your app name
    • Supported account types: Accounts in this organizational directory only (Single tenant)
    • Redirect URI: http://localhost
  5. Save
    • Application (client) ID
    • Directory (tenant) ID
    • Client secret (create a new one in the "Certificates & secrets" tab)

API permissions

  1. Go to API permissions
  2. Click on "Add a permission"
  3. Select "Microsoft Graph" => Application permissions
  4. Select Mail.Send
  5. Click on "Grant admin consent"

Register mailer

Just rewrite the default mailer service in your neon file.

services:
	mail.mailer: Adbros\MicrosoftMailer\MicrosoftMailer(
		tenantId: 'tenant_id'
		clientId: 'client_id'
		clientSecret: 'client_secret'
		defaultSender: 'default_sender_email'
	)

Usage

Use as standard Nette Mailer.

<?php

use Nette\Mail\Mailer;
use Nette\Mail\Message;

class SomeClass
{

    public function __construct(
        private Mailer $mailer,
    ) 
    {    
    }
    
    public function sendEmail(): void
    {
        $message = new Message();
        $message->setSubject('Hello World!');
        $message->setHtmlBody('<h1>Hello World!</h1>');
        $message->addTo('john.doe@example.org');
        
        $this->mailer->send($message);
    }
    
}

No release at this moment. Try to create first one.

price-tag-2-line

Badges

guide-fill

Dependencies

php (>=8.1)
nette/mail (^3.0 || ^4.0)
Componette Componette felix@nette.org