Cloud Mail

repository·main·Indexed 12 days ago

https://github.com/maillab/cloud-mail

A low-cost, responsive email service deployed on Cloudflare Workers. It features multi-email address management under a single domain, attachment support via Cloudflare R2, automated verification code recognition using Workers AI, and administrative RBAC. The stack includes Hono, Drizzle ORM, Vue3, Element Plus, and Resend for email delivery, utilizing Cloudflare D1 for databases and KV for caching.

Tokens
11K
Snippets
51
Records
59
Agent score
95%

What's inside Cloud Mail

  1. Overview of Cloud Mail

    main

    Cloud Mail is a responsive email service designed to be deployed on Cloudflare Workers. It allows users to create multiple different email addresses using a single domain, similar to major email platforms, while minimizing server costs by leveraging Cloudflare's serverless infrastructure.

    Key Capabilities

    • Low-Cost Deployment: Runs on Cloudflare Workers (no dedicated server required).
    • Email Management: Send and receive emails with attachment support (stored via Cloudflare R2).
    • Email Sending: Integrated with Resend for bulk sending and attachments.
    • Admin & Security: RBAC-based access control, Turnstile CAPTCHA integration, and user/email management.
    • Automation: Email push notifications to Telegram bots and automatic verification code recognition via Workers AI.
    • Open API: Supports batch user creation and multi-condition email queries.
  2. Cloud Mail Core Features

    main

    Cloud Mail provides a comprehensive suite of email management features:

    • Email Sending: Integrated with Resend for sending emails, supporting bulk sending, embedded images, and attachments with status tracking.
    • Attachment Support: Uses Cloudflare R2 object storage for saving and downloading attachments.
    • Email Forwarding: Supports forwarding received emails to Telegram bots or other email providers.
    • Admin Management: Includes RBAC (Role-Based Access Control) to manage users and emails, with resource limits.
    • Automated Verification: Uses Workers AI to automatically recognize verification codes within emails.
    • Open API: Provides APIs for bulk user generation and multi-condition email querying.
    • Security: Integrates Cloudflare Turnstile for human verification to prevent bot registrations.
    • Data Visualization: Uses ECharts to visualize system data and user email growth.
    • Customization: Allows customizing website titles, login backgrounds, and transparency settings.
  3. Cloud Mail Project Structure

    main

    The repository is divided into two main packages:

    mail-worker (Backend)

    Located in the mail-worker directory, this is the Cloudflare Worker backend project. Key directories include:

    • src/api: API interface layer.
    • src/dao: Data access layer.
    • src/email: Email processing and reception.
    • src/hono: Web framework configuration, interceptors, and global exception handling.
    • src/security: Identity and permission authentication.
    • src/service: Business logic service layer.
    • wrangler.toml: Project configuration for Cloudflare.

    mail-vue (Frontend)

    Located in the mail-vue directory, this is the Vue3 frontend project. Key directories include:

    • src/request: API interfaces.
    • src/views: Page components.
    • src/store: Global state management.
    • src/perm: Permission authentication.
    cloud-mail
    ├── mail-worker
    │   ├── src
    │   │   ├── api
    │   │   ├── const
    │   │   ├── dao
    │   │   ├── email
    │   │   ├── entity
    │   │   ├── error
    │   │   ├── hono
    │   │   ├── i18n
    │   │   ├── init
    │   │   ├── model
    │   │   ├── security
    │   │   ├── service
    │   │   ├── template
    │   │   ├── utils
    │   │   └── index.js
    │   ├── package.json
    │   └── wrangler.toml
    ├── mail-vue
    │   ├── src
    │   │   ├── axios
    │   │   ├── components
    │   │   ├── echarts
    │   │   ├── i18n
    │   │   ├── init
    │   │   ├── layout
    │   │   ├── perm
    │   │   ├── request
    │   │   ├── router
    │   │   ├── store
    │   │   ├── utils
    │   │   ├── views
    │   │   ├── app.vue
    │   │   ├── main.js
    │   │   └── style.css
    │   ├── package.json
    └── └── env.release
  4. Obtain Cloudflare API Token and Account ID

    main

    To deploy the service, you need specific credentials from your Cloudflare dashboard.

    Cloudflare API Token

    1. Visit the Cloudflare API Tokens page.
    2. Create a new API token.
    3. Use the "Edit Cloudflare Workers" template.
    4. Ensure you add the necessary permissions as required by the service (refer to the template settings).
    5. Save the token and add it to your GitHub Secrets as CLOUDFLARE_API_TOKEN.

    Cloudflare Account ID

    1. Locate your Account ID in the Cloudflare Dashboard account settings.
    2. Add this value to your GitHub Secrets as CLOUDFLARE_ACCOUNT_ID.
  5. Deploy cloud-mail via GitHub Actions

    main

    To deploy cloud-mail to Cloudflare Workers using GitHub Actions, you must first fork or clone the repository and configure several required secrets in your GitHub repository settings.

    Setup Steps

    1. Fork or clone the cloud-mail repository.
    2. In your GitHub repository, navigate to SettingsSecrets and variablesActionsNew repository secret.
    3. Add the required secrets listed in the reference table below.
    4. Once secrets are configured, go to the Actions tab in your repository and manually run the workflow.

    Database Initialization

    If you do not provide the INIT_URL secret, you must manually initialize your database after deployment by visiting the following URL in your browser: https://<your-project-domain>/api/init/<your_jwt_secret>

    Manual initialization URL format:
    https://<your-project-domain>/api/init/<your_jwt_secret>
  6. How to translate TinyMCE language files

    main

    To translate language files for TinyMCE within this project, do not modify the files in mail-vue/public/tinymce/langs/ directly. Instead, use the official Crowdin service to submit translations. This ensures that changes are managed correctly through the proper localization workflow.

    https://crowdin.com/project/tinymce
  7. Deploy Cloud Mail

    main

    To deploy Cloud Mail, refer to the official Deployment Guide. The project is split into two main components:

    1. mail-worker: The backend worker project (Hono-based API and email processing).
    2. mail-vue: The frontend Vue project.

    Configuration is managed via wrangler.toml in the mail-worker directory and environment variables (see env.release for reference).

  8. Configure GitHub Secrets for cloud-mail deployment

    main

    The following secrets must be configured in your GitHub repository to enable deployment to Cloudflare Workers and proper service operation.

    Secret NameRequiredPurpose
    CLOUDFLARE_API_TOKENCloudflare API token (requires Workers and related resource permissions)
    CLOUDFLARE_ACCOUNT_IDYour Cloudflare Account ID
    D1_DATABASE_IDYour D1 database ID
    KV_NAMESPACE_IDYour KV namespace ID
    R2_BUCKET_NAMEYour R2 bucket name
    DOMAINDomain(s) used for the mail service (e.g., example.com; use commas to separate multiple domains)
    ADMINYour administrator email address (e.g., admin@example.com)
    JWT_SECRETA long random string used for generating and validating JWTs
    INIT_URL(Optional) The Worker URL used to initialize the database after deployment
  9. Manage user profile and password via API client

    main

    The mail-vue package provides API client methods for managing user profile information, resetting passwords, and deleting user accounts. These methods use an underlying http client (Axios) to communicate with the backend.

    import { loginUserInfo, resetPassword, userDelete } from 'mail-vue/src/request/my.js';
    
    // Fetch current user info
    const userInfo = await loginUserInfo();
    
    // Reset password
    await resetPassword('new_secure_password');
    
    // Delete user account
    await userDelete();
  10. Update user properties and status

    main

    These methods allow for modifying existing user attributes, credentials, or operational status via PUT requests.

    • userSetPwd(params): Updates a user's password. Expects a params object containing the necessary credentials/identifiers.
    • userSetStatus(params): Updates the account status (e.g., active/inactive).
    • userSetType(params): Updates the user type/role.
    • userRestSendCount(userId): Resets the email sending count for a specific user. Expects an object { userId }.
    export function userSetPwd(params) {
        return http.put('/user/setPwd', params)
    }
    
    export function userSetStatus(params) {
        return http.put('/user/setStatus', params)
    }
    
    export function userSetType(params) {
        return http.put('/user/setType', params)
    }
    
    export function userRestSendCount(userId) {
        return http.put('/user/resetSendCount', {userId})
    }