socialsquared/office365mailer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

socialsquared/office365mailer

最新稳定版本:v2.0.0

Composer 安装命令:

composer require socialsquared/office365mailer

包简介

Mail driver for Laravel to send emails using the Microsoft Graph API without user authentication and SMTP

README 文档

README

A custom mail driver for Laravel that uses the Microsoft Graph API to send emails without requiring SMTP or user authentication.

Latest Version on Packagist GitHub License

Installation

You can install the package via composer:

composer require socialsquared/office365mailer

Configuration

Setup Azure App Registration

To use this package you need to create an app in the Azure portal and grant the required permissions:

  1. Open the Azure Active Directory Portal with your Office365 Admin account
  2. Go to App registrations and create a new app
  3. Add the required permissions:
    • Mail.Send (Application permission)
    • User.Read (Application permission)
  4. Apply the Admin consent for these permissions for your organization
  5. Create a new client secret and save the secret along with the client ID and tenant ID. You will need these for your .env file

For detailed instructions, follow the official Microsoft guide on service-to-service auth with Microsoft Graph.

Laravel Configuration

Publish the config file:

php artisan vendor:publish --provider="Socialsquared\Office365mailer\Office365MailerServiceProvider"

Update your config/mail.php file to add the Office365 mailer:

'mailers' => [
    // ... other mailers
    
    'office365' => [
        'transport' => 'office365',
    ],
],

Then add the following to your .env file:

MAIL_MAILER=office365
MAIL_FROM_ADDRESS=sender@yourdomain.com

OFFICE365MAIL_TENANT=your-tenant-id
OFFICE365MAIL_CLIENT_ID=your-client-id
OFFICE365MAIL_SECRET=your-client-secret

Features

  • Easy Integration: Seamlessly integrates with Laravel's Mail system
  • No SMTP Required: Uses Microsoft Graph API instead of SMTP for better reliability
  • Azure Authentication: Supports application-only authentication using client credentials
  • Default Senders: Configure default sender emails and names
  • Automatic Retries: Built-in retry mechanism for failed email deliveries
  • Comprehensive Logging: Detailed logging of email delivery status
  • Batch Sending: Configure maximum recipients per batch
  • Security Features: Email validation to prevent injection attacks
  • Attachment Support: Send attachments with proper size validation
  • Receipt Options: Support for read and delivery receipt requests
  • Email Priority: Set email importance levels (high, normal, low)
  • Utility Helpers: Additional email utilities for common tasks

Usage

Once configured, you can use Laravel's standard Mail facade:

use Illuminate\Support\Facades\Mail;

Mail::to('recipient@example.com')
    ->subject('Test Email')
    ->send(new \App\Mail\TestEmail());

Important Note: Custom sender names are not supported by the Microsoft Graph API. While you can specify a sender name in your Laravel code, it will not be used when sending the email. The only way to change the sender display name is by modifying the display name of the user account in the Microsoft 365 Admin Center. This is a limitation of the Microsoft Graph API, not this package.

Advanced Features

use Socialsquared\Office365mailer\Utils\EmailHelpers;

// Create an email with read receipt
$email = EmailHelpers::createEmail('sender@example.com', 'Sender Name');
$email = EmailHelpers::addReadReceiptRequest($email, 'receipts@example.com');
$email = EmailHelpers::setImportance($email, 'high');

// Send the email
Mail::to('recipient@example.com')
    ->send(new \App\Mail\CustomEmail($email));

Requirements

  • PHP 7.4+
  • Laravel 8.0+
  • Microsoft Graph PHP SDK 2.14+
  • Azure AD application with appropriate permissions

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 405
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-22