overtrue/laravel-mail-aliyun

Aliyun DrirectMail Transport for Laravel Application.
9,214 70
Install
composer require overtrue/laravel-mail-aliyun
Latest Version:4.0.0
PHP:^8.3
Laravel:13
Older releases:5 – 11
License:MIT
Last Updated:Oct 4, 2026
Links: GitHub  ·  Packagist
Maintainer: overtrue

Sponsor me

Installing

$ composer require overtrue/laravel-mail-aliyun -vvv

Configuration

API documention: https://help.aliyun.com/document_detail/29435.html

config/services.php

    'directmail' => [
        'key' => env('ALIYUN_ACCESS_KEY_ID'),
        'secret' => env('ALIYUN_ACCESS_KEY_SECRET'),
        'region_id' => env('ALIYUN_REGION_ID'),
        'from_address' => env('ALIYUN_FROM_ADDRESS'),
        'from_alias' => env('ALIYUN_FROM_ALIAS'),
    ],

AccessKeyID 和 AccessKeySecret 由阿里云官方颁发给用户的 AccessKey 信息(可以通过阿里云控制台用户信息管理中查看和管理).

Usage

Set default mail driver and configuration:

.env

MAIL_MAILER=directmail

ALIYUN_ACCESS_KEY_ID=  #AccessKeyID
ALIYUN_ACCESS_KEY_SECRET= #AccessKeySecret
ALIYUN_REGION_ID= #RegionID: cn-hangzhou, ap-southeast-1, ap-southeast-2
ALIYUN_FROM_ADDRESS= #FromAddress
ALIYUN_FROM_ALIAS= #FromAlias

Add a mailer in config/mail.php:

'mailers' => [
    'directmail' => ['transport' => 'directmail'],
],

This version supports Laravel 13 and PHP 8.3+ using Symfony Mailer. To and CC recipients are sent through the API's ToAddress field; the API does not preserve a separate CC header. This transport rejects BCC, envelope-only recipients absent from To/CC headers, and attachments rather than silently dropping them or exposing blind recipients. Use SMTP when these features are needed. Custom message callbacks should use withSymfonyMessage() and Symfony's Email.

TagName

use Overtrue\LaravelMailAliyun\HasTagName;
class VerifyMail extends Mailable{
    use HasTagName;
    public function build()
    {
        $this->tagName('alreadyDefinedTag');
        return $this->text('mails.verify');
    }
}

Please reference the official doc: Laravel Sending mail

:heart: Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 :heart:

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

License

MIT

Tests

composer install
composer test

The test suite uses a mocked HTTP handler and does not send real email.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released PHP Laravel License
4.0.0 ^8.3 ^13.0 MIT
3.1.0 ^9.0|^10.0|^11.0 MIT
3.0.0 ^9.0|^10.0 MIT
2.1.2 ^7.0 || ^8.0 MIT
2.1.0 ^7.0 || ^8.0 MIT