定制 iperamuna/mailu-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

iperamuna/mailu-laravel

最新稳定版本:v1.0.0

Composer 安装命令:

composer require iperamuna/mailu-laravel

包简介

A Laravel SDK for the Mailu API

README 文档

README

Latest Version on Packagist Total Downloads License

A high-performance, developer-friendly Laravel SDK for the Mailu API. Designed for Indunil Peramuna with focus on DTOs, type safety, and clean architecture.

✨ Features

  • PHP: ^8.2
  • Laravel: ^12.0 || ^13.0
  • 🚀 Full API Coverage: Support for Users, Domains, Aliases, Alternatives, Relays, and Tokens.
  • 🛡️ Type-Safe DTOs: Heavily utilizes spatie/laravel-data for structured, validated data handling.
  • ⚡ Built-in Caching: Intelligent caching of GET requests to optimize performance.
  • 🧱 Modular Architecture: Cleanly separated concerns using traits (HasUsers, HasDomains, etc.).
  • 🧪 Pest Powered: Comprehensive test suite written in Pest PHP.
  • 🧩 Clean Facade: Intuitive Mailu facade for standard operations.

📦 Installation

You can install the package via composer:

composer require iperamuna/mailu-laravel

⚙️ Configuration

Publish the config file:

php artisan vendor:publish --tag="mailu-config"

Add your credentials to .env:

MAILU_API_URL=https://mail.yourdomain.com/api/v1
MAILU_API_TOKEN=your_token_here
MAILU_CACHE_ENABLED=true

📖 Usage Examples

1. Simple Facade Usage

The most common way to interact with the SDK.

use Iperamuna\Mailu\Facades\Mailu;

// List all users
$users = Mailu::listUsers(); // Returns Collection<UserData>

// Create a new domain
Mailu::createDomain([
    'name' => 'example.com',
    'comment' => 'Managed by Laravel',
]);

// Generate DKIM keys
Mailu::generateDKIM('example.com');

2. Usage in a Controller

Inject the MailuService directly into your controller methods.

namespace App\Http\Controllers;

use Iperamuna\Mailu\MailuService;
use Illuminate\Http\Request;

class MailboxController extends Controller
{
    public function index(MailuService $mailu)
    {
        return view('mailboxes.index', [
            'users' => $mailu->listUsers(),
        ]);
    }

    public function store(Request $request, MailuService $mailu)
    {
        $mailu->createUser($request->only(['email', 'raw_password', 'displayed_name']));
        
        return back()->with('success', 'Mailbox created!');
    }
}

3. Usage in a Filament Resource

Ideal for building custom admin interfaces. Since Mailu returns an array/collection, you can use Filament's Table Builder with custom data.

namespace App\Filament\Resources;

use Filament\Resources\Resource;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Iperamuna\Mailu\Facades\Mailu;
use Iperamuna\Mailu\Data\UserData;

class MailboxResource extends Resource
{
    public static function table(Table $table): Table
    {
        return $table
            ->content(fn () => Mailu::listUsers()) // Fetch from API
            ->columns([
                TextColumn::make('email')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('displayed_name')
                    ->label('Name'),
                TextColumn::make('quota_bytes_used')
                    ->label('Usage')
                    ->formatStateUsing(fn ($state) => number_format($state / 1024 / 1024, 2) . ' MB'),
            ])
            ->actions([
                \Filament\Tables\Actions\DeleteAction::make()
                    ->action(fn (UserData $record) => Mailu::deleteUser($record->email)),
            ]);
    }
}

🧪 Testing

composer test

🔒 Security

If you discover any security-related issues, please email iperamuna@gmail.com.

👤 Credits

📄 License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固