npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

etm-email-service

v1.0.0

Published

NestJS Email Service

Downloads

5

Readme

NestJS Email Service

This project provides an email service using NestJS, designed to handle both individual and bulk email requests. It integrates with external email services and allows configuration through environment variables.

Table of Contents

  1. Project Overview
  2. Features
  3. Prerequisites
  4. Installation
  5. Configuration
  6. Usage
  7. Testing

Project Overview

This NestJS application provides endpoints to send emails using a configurable email service. It supports sending both single and bulk emails. The email service is designed to be flexible and can be adapted to various email providers such as Nodemailer, Mailgun, and Postmark.

Features

  • Single Email Sending: Send individual emails with customizable options.
  • Bulk Email Sending: Send emails to multiple recipients with a single request.
  • Configurable: Use environment variables to configure the email service.
  • Logging: Includes logging for debugging and error reporting.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js: Version 14 or higher.

  • NestJS CLI: Install the NestJS CLI globally using npm: npm install -g @nestjs/cli

  • Email Service: Access to an email service provider and necessary API keys.

Installation

  1. Clone the Repository:

    git clone https://github.com/wondwosen-bewketu/Email-service.git

  2. Navigate to the Project Directory**:

    cd Email-service

  3. Install Dependencies**:

    npm install

  4. Set Up Environment Variables**: Create a .env file in the root directory and add your email service configuration:

    EMAIL_PROVIDER=nodemailer
    SMTP_HOST=mail.example.com
    SMTP_PORT=587
    [email protected]
    SMTP_PASS=yourpassword
    [email protected]
    MAILGUN_API_KEY=your-mailgun-api-key
    MAILGUN_DOMAIN=your-mailgun-domain
    POSTMARK_API_KEY=your-postmark-api-key

Configuration

Configuration is handled through the email.config.ts file and environment variables. The EmailService is initialized with the settings from these files. Example email.config.ts

import { ConfigService } from '@nestjs/config';

export class EmailConfig {
  static getEmailConfig(configService: ConfigService) {
    return {
      provider: configService.get<string>('EMAIL_PROVIDER'),
      smtpHost: configService.get<string>('SMTP_HOST'),
      smtpPort: configService.get<number>('SMTP_PORT'),
      smtpUser: configService.get<string>('SMTP_USER'),
      smtpPass: configService.get<string>('SMTP_PASS'),
      fromEmail: configService.get<string>('FROM_EMAIL'),
      mailgunApiKey: configService.get<string>('MAILGUN_API_KEY'),
      mailgunDomain: configService.get<string>('MAILGUN_DOMAIN'),
      postmarkApiKey: configService.get<string>('POSTMARK_API_KEY'),
    };
  }
}

Usage

Endpoints

Send Email

  • URL: /emails/send-email
  • Method: POST
  • Description: Sends a single email.
  • Request Body:
    {
      "to": "[email protected]",
      "subject": "Your Subject Here",
      "context": { "key1": "value1" },
      "text": "Plain text content",
      "customTemplatePath": "path/to/template.hbs"
    }

Send Bulk Email

  • URL: /emails/send-bulk-email
  • Method: POST
  • Description: Sends emails to multiple recipients.
  • Request Body:
    {
      "to": ["[email protected]", "[email protected]"],
      "subject": "Your Subject Here",
      "context": { "key1": "value1" },
      "text": "Plain text content",
      "customTemplatePath": "path/to/template.hbs"
    }

Starting the Server

To start the server, use the following command:

npm run start