{"id":29293564,"url":"https://github.com/aulanchik/mail-sender","last_synced_at":"2026-05-07T06:31:44.360Z","repository":{"id":301718454,"uuid":"907606836","full_name":"aulanchik/mail-sender","owner":"aulanchik","description":"Service for sending out HTML templated emails","archived":false,"fork":false,"pushed_at":"2025-06-28T11:01:30.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T11:06:16.827Z","etag":null,"topics":["express","form-data","handlebars","mailgunjs","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aulanchik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-24T01:32:20.000Z","updated_at":"2025-06-28T11:01:33.000Z","dependencies_parsed_at":"2025-06-28T12:22:05.479Z","dependency_job_id":"af79643f-62bb-45be-886a-47ebb51896e4","html_url":"https://github.com/aulanchik/mail-sender","commit_stats":null,"previous_names":["aulanchik/mail-sender"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aulanchik/mail-sender","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aulanchik%2Fmail-sender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aulanchik%2Fmail-sender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aulanchik%2Fmail-sender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aulanchik%2Fmail-sender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aulanchik","download_url":"https://codeload.github.com/aulanchik/mail-sender/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aulanchik%2Fmail-sender/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32725955,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","form-data","handlebars","mailgunjs","nodejs"],"created_at":"2025-07-06T11:06:12.924Z","updated_at":"2026-05-07T06:31:44.347Z","avatar_url":"https://github.com/aulanchik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mail-sender\n\nThis repository contains a simple Node.js and Express application that serves as a mail-sending service using the Mailgun API. It provides an API endpoint to send customized HTML emails to two different recipients simultaneously, using separate Handlebars templates for each.\n\n## Features\n\n*   **Mailgun Integration**: Leverages the Mailgun API for robust email delivery.\n*   **Dynamic Templating**: Uses Handlebars.js to populate HTML email templates with dynamic data.\n*   **Concurrent Sending**: Sends emails to multiple recipients in parallel.\n*   **RESTful API**: Exposes a clean `POST` endpoint to trigger the email sending process.\n*   **Middleware**: Includes `helmet` for security and `morgan` for request logging.\n\n## Project Structure\n\n```\n.\n├── src/\n│   ├── index.js          # Main entry point, sets up Express server and middlewares\n│   ├── configs/\n│   │   └── client.js     # Configures and initializes the Mailgun client\n│   ├── controllers/\n│   │   └── email.js      # Handles the logic for processing the request and sending emails\n│   ├── routes/\n│   │   └── index.js      # Defines the API routes\n│   ├── services/\n│   │   └── mailgun.js    # Service layer abstracting the Mailgun API calls\n│   └── templates/\n│       ├── a.html        # Handlebars template for the first recipient\n│       └── b.html        # Handlebars template for the second recipient\n└── package.json          # Project dependencies and scripts\n```\n\n## Prerequisites\n\n*   Node.js\n*   A Mailgun account with:\n    *   Your API Key\n    *   Your Mailgun Domain\n\n## Getting Started\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/aulanchik/mail-sender.git\ncd mail-sender\n```\n\n### 2. Install dependencies\n\n```bash\nnpm install\n```\n\n### 3. Set up environment variables\n\nCreate a `.env` file in the root directory and add the following configuration. Replace the placeholder values with your actual Mailgun credentials.\n\n```env\n# Server Configuration\nPORT=4000\n\n# Mailgun API Credentials\nMAILGUN_API_KEY=your_mailgun_api_key\nMAILGUN_USERNAME=api\nDOMAIN=your.mailgun.domain.com\n\n# Default Sender Name\nSENDER=\"Your Sender Name\"\n```\n\n### 4. Run the application\n\nFor development with live reloading:\n```bash\nnpm run dev\n```\n\nFor production:\n```bash\nnpm start\n```\n\nThe server will be running on the port specified in your `.env` file (e.g., `http://localhost:4000`).\n\n## API Usage\n\n### Send Emails\n\nSend a `POST` request to the `/api/emails/send-email` endpoint with the recipient details and template data in the request body.\n\n**Endpoint**: `POST /api/emails/send-email`\n\n**Request Body**:\n\n```json\n{\n    \"recepientA\": \"first_email@example.com\",\n    \"recepientB\": \"second_email@example.com\",\n    \"subject\": \"Greetings from Mail Sender!\",\n    \"dataA\": {\n        \"name\": \"Alice\",\n        \"message\": \"This is a special message just for you, Alice.\"\n    },\n    \"dataB\": {\n        \"name\": \"Bob\",\n        \"message\": \"This is a different message tailored for Bob.\"\n    }\n}\n```\n\n#### Field Descriptions:\n- `recepientA` (string, required): The email address for the first recipient.\n- `recepientB` (string, required): The email address for the second recipient.\n- `subject` (string, required): The subject line for both emails.\n- `dataA` (object, required): Data to populate the `a.html` template.\n- `dataB` (object, required): Data to populate the `b.html` template.\n\n#### Example `curl` Request:\n\n```bash\ncurl -X POST http://localhost:4000/api/emails/send-email \\\n-H \"Content-Type: application/json\" \\\n-d '{\n    \"recepientA\": \"alice@example.com\",\n    \"recepientB\": \"bob@example.com\",\n    \"subject\": \"Your Weekly Update\",\n    \"dataA\": {\n        \"name\": \"Alice\",\n        \"message\": \"Here is your update for the week.\"\n    },\n    \"dataB\": {\n        \"name\": \"Bob\",\n        \"message\": \"Please see your weekly summary attached.\"\n    }\n}'\n```\n\n#### Success Response (Status `200 OK`)\n\n```json\n{\n    \"message\": \"Emails sent successfully!\",\n    \"successes\": [\n        {\n            \"id\": \"\u003c20240320183021.1234.5678@your.mailgun.domain.com\u003e\",\n            \"message\": \"Queued. Thank you.\"\n        },\n        {\n            \"id\": \"\u003c20240320183022.9876.5432@your.mailgun.domain.com\u003e\",\n            \"message\": \"Queued. Thank you.\"\n        }\n    ],\n    \"failures\": []\n}\n```\n\n#### Error Responses\n\n- **Status `400 Bad Request`**: If any of the required fields are missing from the request body.\n    ```json\n    {\n        \"error\": \"All fields are required to be filled in.\"\n    }\n    ```\n- **Status `500 Internal Server Error`**: If Mailgun fails to send the emails.\n    ```json\n    {\n        \"error\": \"Failed to send out emails.\",\n        \"details\": \"...\"\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faulanchik%2Fmail-sender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faulanchik%2Fmail-sender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faulanchik%2Fmail-sender/lists"}