notifiablehq/receive-email
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
- Add this to your recipes, you can name it
Install Mailparse. Make sure the user isroot.
apt-get update apt-get install -y php-cli php-mailparse
-
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 showAdvance Settingsto select this. -
Once you have the server ready, open up
Port 25, add your site, and deploy your Laravel app. -
Activate an SSL certificate for your site in Forge (Sites > your site > SSL). Forge uses Let's Encrypt and places certs at:
- Certificate:
/etc/nginx/ssl/your-application-domain.com/server.crt - Private key:
/etc/nginx/ssl/your-application-domain.com/server.key
- Certificate:
-
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 \
--user=forge \
--tls-cert=/etc/nginx/ssl/your-application-domain.com/server.crt \
--tls-key=/etc/nginx/ssl/your-application-domain.com/server.key \
--with-spf
Important: Always pass
--user=forge(or your deploy user) when running withsudo. Without it, the pipe transport will run asroot.
Available options:
| Option | Description |
|---|---|
--user=forge |
The system user Postfix runs the pipe command as. Required when using sudo. |
--tls-cert= |
Path to the TLS certificate file (PEM format). Enables opportunistic TLS for inbound SMTP. |
--tls-key= |
Path to the TLS private key file (PEM format). Must be provided together with --tls-cert. |
--with-spf |
Installs postfix-policyd-spf-python and configures SPF verification for inbound mail. |
-
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 Type Host Value TXT domain-that-receives-email.com v=spf1 mx -all The SPF TXT record tells other mail servers that only your MX host is authorized to send mail for this domain. Even though this is a receive-only server, publishing an SPF record prevents others from spoofing your domain.
Configuration
After publishing the config file, you can tune the following settings in config/receive_email.php:
| Key | Default | Description |
|---|---|---|
message-size-limit |
26214400 (25MB) |
Maximum inbound email size in bytes. Written to Postfix's message_size_limit. |
pipe-concurrency |
4 |
Maximum concurrent pipe processes. Maps to maxproc in master.cf. |
storage-disk |
local |
Filesystem disk for storing raw email files. |
email-table |
emails |
Table name for the Email model. |
sender-table |
senders |
Table name for the Sender model. |
To apply changes to message-size-limit or pipe-concurrency, re-run the setup command.
Research References
Credits
The solutions in this package are inspired by the following projects:
notifiablehq/receive-email 适用场景与选型建议
notifiablehq/receive-email 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 207 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「mailbox」 「inbound email」 「receive email」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 notifiablehq/receive-email 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 notifiablehq/receive-email 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 notifiablehq/receive-email 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Convenience library for postmark inbound email parsing.
Extension conversion of 'EWS' to yii2 extension
Inbound emails for Symfony apps with Sendgrid and Mailjet support
Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
API to process Postmark Inbound Webhooks.
PhpImap\Mailbox Symfony integration.
统计信息
- 总下载量: 207
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-01