{"id":25417535,"url":"https://github.com/arnavsharma2711/mailer-api","last_synced_at":"2026-04-12T05:34:00.437Z","repository":{"id":216030764,"uuid":"740270822","full_name":"arnavsharma2711/mailer-api","owner":"arnavsharma2711","description":"Mailer App API is a simple Node.js application using Express and Nodemailer to send emails. It provides an endpoint to send emails with a specified recipient, subject, and HTML content.","archived":false,"fork":false,"pushed_at":"2024-10-10T17:26:34.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T17:59:45.936Z","etag":null,"topics":["expressjs","jwt","nodejs","nodemailer"],"latest_commit_sha":null,"homepage":"https://mailer-api-arnavsharma2711.vercel.app/","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/arnavsharma2711.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}},"created_at":"2024-01-08T01:51:35.000Z","updated_at":"2024-10-10T17:26:37.000Z","dependencies_parsed_at":"2024-01-08T05:06:45.540Z","dependency_job_id":"09149669-694a-4cf4-a567-92a87902b3bd","html_url":"https://github.com/arnavsharma2711/mailer-api","commit_stats":null,"previous_names":["arnavsharma2711/mailer-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavsharma2711%2Fmailer-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavsharma2711%2Fmailer-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavsharma2711%2Fmailer-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnavsharma2711%2Fmailer-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnavsharma2711","download_url":"https://codeload.github.com/arnavsharma2711/mailer-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252577667,"owners_count":21770851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["expressjs","jwt","nodejs","nodemailer"],"created_at":"2025-02-16T17:59:54.236Z","updated_at":"2025-12-30T23:05:02.963Z","avatar_url":"https://github.com/arnavsharma2711.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mailer App API\n\nMailer App API is a simple Node.js application using Express and Nodemailer to send emails. It provides an endpoint to send emails with a specified recipient, subject, and HTML content. It now includes token-based authentication with expiry to secure the `/send-email` endpoint.\n\n## Prerequisites\n\n- Node.js installed on your machine\n- Gmail account for sending emails (or update the email service in the code accordingly)\n\n## Getting Started\n\n1. Clone this repository to your local machine.\n2. Install dependencies by running:\n  ```bash\n    npm install\n  ```\n3. Create a `.env` file in the root directory and set the following variables:\n   ```env\n    PORT=3000\n    GMAIL_USER=your-email@gmail.com\n    GMAIL_PASS=your-email-password\n    AUTH_TOKEN_SECRET=your-secret-token\n   ```\n4. Replace `your-email@gmail.com`, `your-email-password`, and `your-secret-token` with your Gmail credentials and a secret token for API authentication.\n\n## Running the Application\nStart the server by running:\n```bash\nnpm start\n```\nThe server will run on http://localhost:3000 or the port specified in your `.env` file.\n\n## API Endpoints\n\n### 1. Welcome Page\n- **URL:** `/`\n- **Method:** `GET`\n- **Description:** Displays a welcome message.\n- **Example:** `http://localhost:3000/`\n\n### 2. Send Email\n- **URL:** `/send-email`\n- **Method:** `POST`\n- **Description:** Sends an email with the provided details. Requires authentication using the `x-auth-token` header.\n- **Request Headers:**\n  ```json\n  {\n    \"x-auth-token\": \"jwt-token\"\n  }\n  ```\n- **Request Body:**\n  ```json\n  {\n    \"subject\": \"Your Subject\",\n    \"html\": \"\u003cp\u003eYour HTML content\u003c/p\u003e\"\n  }\n  ```\n- **Example:** `http://localhost:3000/send-email`\n\n### 3. 404 Page\n- **URL:** `/*`\n- **Method:** `GET`\n- **Description:** Displays a 404 error message for any undefined routes.\n- **Example:** `http://localhost:3000/undefined-route`\n\n## Generating JWT Token\n\nTo use the `/send-email` endpoint from your application, you need to generate a JWT token. Here's how you can do it:\n\n```javascript\nconst jwt = require('jsonwebtoken');\n\nconst payload = {\n  to: 'test@email.com'\n};\n\nconst options = {\n  expiresIn: '1h',\n};\n\nconst authTokenSecret = \"your-secret-token\";\nconst jwtToken = jwt.sign(payload, authTokenSecret, options);\n```\nIn this code, `payload` is an object that contains the email address to which you want to send the email. `options` is an object that specifies the expiry time of the token. `jwt.sign()` is a method provided by the jsonwebtoken package that generates a JWT token. It takes three arguments: the payload, the secret key, and the options.\n\nRemember to replace `'test@email.com'` with the actual email address and `your-secret-token` with your actual secret key.\n\n## Authentication\nToken-based authentication is implemented using the `x-auth-token` header. Include this header with the secret token in your requests to the `/send-email` endpoint. The token has an expiry time, after which it will no longer be valid.\n\n## CORS Configuration\nThe server is configured to allow Cross-Origin Resource Sharing (CORS) to any origin.\n\n## Author\n- Arnav Sharma (@arnavsharma2711)\n\nFeel free to use and modify the code according to your needs. If you encounter any issues or have suggestions, please create an issue or reach out to the author.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnavsharma2711%2Fmailer-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnavsharma2711%2Fmailer-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnavsharma2711%2Fmailer-api/lists"}