arkadip/email-channel 问题修复 & 功能扩展

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

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

arkadip/email-channel

最新稳定版本:v1.0.1

Composer 安装命令:

composer require arkadip/email-channel

包简介

Laravel Email Channel Package

README 文档

README

A modular Laravel package for sending, receiving, and managing emails using IMAP and SMTP — with database storage, duplicate prevention, incremental UID-based fetching, API endpoints, and an optional dashboard UI.

✨ Features

# Feature
1 Fetch incoming emails via IMAP
2 Send emails via SMTP
3 Store emails in database
4 Prevent duplicate email processing
5 Incremental fetching using UID tracking
6 Store metadata (subject, UID, etc.)
7 API endpoints for email operations
8 Optional dashboard UI
9 Auto-fetch emails via Laravel Scheduler
10 Modular and reusable package architecture

🧰 Prerequisites

Ensure the following are installed before getting started:

🚀 Installation & Setup

Step 1 — Create Laravel Application

composer create-project laravel/laravel email-channel-app
cd email-channel-app

Step 2 — Install the Package

composer require arkadip/email-channel

⚠️ If testing locally before publishing to Packagist, add a repositories entry in your composer.json pointing to the local path.

Step 3 — Setup Database (XAMPP + phpMyAdmin)

  1. Start XAMPP — enable both Apache and MySQL
  2. Open phpMyAdmin at http://localhost/phpmyadmin
  3. Create a new database named:
email_channel_db

Step 4 — Configure .env

Open email-channel-app/.env and set the following:

🗄️ Database

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=email_channel_db
DB_USERNAME=root
DB_PASSWORD=

📥 IMAP — Incoming Emails

IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_ENCRYPTION=ssl
IMAP_USERNAME=your-email@gmail.com
IMAP_PASSWORD=your-app-password

⚠️ Use an App Password, not your Gmail account password.
Don't forget to enable IMAP in Gmail Settings → See all settings → Forwarding and POP/IMAP.

📤 SMTP — Sending Emails

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=your-email@gmail.com
MAIL_FROM_NAME="Email Channel"

Step 5 — Run Migrations

php artisan migrate

This creates the following tables:

  • messages
  • message_metas

Step 6 — Setup Scheduler (Auto Fetch)

Open bootstrap/app.php and add the following before ->create():

->withSchedule(function ($schedule) {
    $schedule->call(function () {
        app(\Arkadip\EmailChannel\Services\ImapService::class)->fetchEmails();
    })->everyTenSeconds(); // near real-time fetching
})

Then start the scheduler:

php artisan schedule:work

Step 7 — Setup Routes

Open routes/web.php and add:

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('email-channel::dashboard');
});

Step 8 — Run the Application

php artisan serve

Visit: http://127.0.0.1:8000/email-dashboard

🎯 Testing Features

Feature Description
Send Email Use the dashboard form — sent via SMTP and stored in DB
Receive Email Fetched via IMAP, stored in DB, duplicates prevented
Auto Fetch Scheduler runs automatically, only fetches new emails
Real-time UI Dashboard auto-updates via polling

📦 API Endpoints

Method Route Purpose
GET /email-channel/emails Retrieve stored emails
POST /email-channel/send Send an email
POST /email-channel/fetch Trigger a manual fetch
GET /email-channel/dashboard View the dashboard UI

🧠 Key Concepts

🔁 Incremental Fetch (UID-based)

Rather than re-fetching all emails on every run:

  • ✔ Only new emails are fetched
  • ✔ Uses UID tracking to resume from last position
  • ✔ Efficient and scalable for production use

🔐 Security Best Practices

  • Never expose your .env file
  • Always use App Passwords for Gmail
  • Do not commit credentials to version control

⚠️ Common Issues

❌ Emails not fetching
  • Enable IMAP in Gmail Settings
  • Use an App Password, not your account password
  • Double-check IMAP credentials in .env
❌ MySQL not starting
  • Restart XAMPP
  • Check for port conflicts (default: 3306)
  • Fix corrupted tables via phpMyAdmin if needed
❌ Package not found
composer dump-autoload
composer update
❌ Scheduler not running
php artisan schedule:work

🗒️ Notes

  • Package is auto-discovered by Laravel — no manual provider registration needed
  • Views are optional and fully customizable
  • Scheduler is controlled entirely by the host application

✅ Final Result

A fully working email system with Laravel package integration, real-time email fetching, and a clean modular architecture.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固