notifiablehq/receive-email 问题修复 & 功能扩展

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

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

notifiablehq/receive-email

最新稳定版本:0.15.2

Composer 安装命令:

composer require notifiablehq/receive-email

包简介

Let your Laravel app receive emails.

README 文档

README

Let your Laravel app receive emails.

Installation

composer require notifiablehq/receive-email

Usage

1. Publish Config and Migrations

Publish the configuration and migration files:

php artisan vendor:publish --provider="Notifiable\\ReceiveEmail\\ReceiveEmailServiceProvider" --tag=receive-email

Then run the migrations:

php artisan migrate

2. Listen for Incoming Emails

Whenever an email is received, the package will dispatch the Notifiable\\ReceiveEmail\\Events\\EmailReceived event. On Laravel 11 and above, you should use a listener class:

Create the Listener

Generate a listener class:

php artisan make:listener HandleIncomingEmail

Then implement the handle method:

namespace App\Listeners;

use Notifiable\ReceiveEmail\Events\EmailReceived;

class HandleIncomingEmail
{
    public function handle(EmailReceived $event): void
    {
        $email = $event->email;
        
        \Log::info('Received email with subject: ' . $email->parsedMail()->subject());
    }
}

3. Accessing Email Data

The Email model gives you access to sender, recipients, subject, and body through the parsedMail method. Example:

/** @var \Notifiable\ReceiveEmail\Contracts\ParsedMailContract $mail */
$mail = $email->parsedMail();

$subject = $mail->subject();
$textBody = $mail->text();
$htmlBody = $mail->html();
$recipients = $mail->recipients();

Forge Deployment

  1. Add this to your recipes, you can name it Install Mailparse. Make sure the user is root.
apt-get update
apt-get install -y php-cli php-mailparse
  1. If you already have an existing server, run this recipe on that server. Otherwise, create a new server and make sure to select this recipe as a Post-Provision Recipe. You'll have to show Advance Settings to select this.

  2. Once you have the server ready, open up Port 25, add your site, and deploy your Laravel app.

  3. SSH into your Forge server and go to your site directory. Then run the setup command as a super user:

sudo php artisan notifiable:setup-postfix domain-that-receives-email.com
  1. Add the following DNS records to your domain:

    Type Host Value
    A your-application-domain.com your.forge.ip.address
    Type Host Value Priority
    MX domain-that-receives-email.com your-application-domain.com 10

Research References

Credits

The solutions in this package are inspired by the following projects:

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-01