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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cedric-castro/azure-email-service

v1.0.0

Published

Azure email service wrapper for Microsoft Graph API

Readme

Azure Email Service

A simple and lightweight TypeScript/JavaScript wrapper for sending emails via Microsoft Graph API using Azure AD authentication.

Installation

npm install @cedric-castro/azure-email-service

Prerequisites

You need to have:

  1. An Azure AD application with client credentials
  2. Microsoft Graph API permissions: Mail.Send
  3. A user account with a mailbox in your tenant

Usage

TypeScript

import { AzureEmailService } from '@cedric-castro/azure-email-service';

const emailService = new AzureEmailService({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  tenantId: 'your-tenant-id',
  maxRetries: 3 // optional, default is 2
});

// Send email
await emailService.sendEmail({
  fromEmail: '[email protected]',
  toEmail: ['[email protected]'],
  subject: 'Hello from Azure',
  body: '<h1>Hello!</h1><p>This is a test email.</p>',
  senderName: 'John Doe', // optional
  cc: ['[email protected]'], // optional
  bcc: ['[email protected]'], // optional
  replyTo: '[email protected]', // optional
  attachments: [] // optional
});

JavaScript

const { AzureEmailService } = require('@cedric-castro/azure-email-service');

const emailService = new AzureEmailService({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  tenantId: 'your-tenant-id'
});

emailService.sendEmail({
  fromEmail: '[email protected]',
  toEmail: ['[email protected]'],
  subject: 'Hello',
  body: '<p>Test email</p>'
})
.then(() => console.log('Email sent!'))
.catch(err => console.error('Error:', err));

API

Constructor

new AzureEmailService(config: AzureEmailServiceConfig)

Config options: | Parameter | Type | Required | Description | | :--- | :--- | :---: | :--- | | clientId | string | ✅ Yes | Azure AD application client ID | | clientSecret | string | ✅ Yes | Azure AD application client secret | | tenantId | string | ✅ Yes | Azure AD tenant ID | | maxRetries | number | ❌ No | Maximum retry attempts (Default: 2) |

sendEmail

sendEmail(params: TAzureSendMail): Promise<boolean>

Parameters: | Parameter | Type | Required | Description | | :--- | :--- | :---: | :--- | | fromEmail | string | ✅ Yes | Sender email address | | toEmail | string[] | ✅ Yes | Array of recipient email addresses | | body | string | ✅ Yes | Email body in HTML format | | subject | string | ❌ No | Email subject | | senderName | string | ❌ No | Display name for sender | | cc | string[] | ❌ No | CC recipients | | bcc | string[] | ❌ No | BCC recipients | | replyTo | string | ❌ No | Reply-to address | | attachments | AzureEmailAttachment[] | ❌ No | Email attachments |

Returns: Promise<boolean> - Returns true if email sent successfully

Throws: Error if email fails to send after all retry attempts

Azure Setup

  1. Register an application in Azure AD
  2. Add API permissions: Microsoft Graph > Application permissions > Mail.Send
  3. Grant admin consent for the permissions
  4. Create a client secret
  5. Note down: Client ID, Client Secret, and Tenant ID

Error Handling

try {
  await emailService.sendEmail({
    fromEmail: '[email protected]',
    toEmail: ['[email protected]'],
    subject: 'Test',
    body: '<p>Hello</p>'
  });
  console.log('Success!');
} catch (error) {
  console.error('Failed to send email:', error.message);
}

Features

| Feature | Description | Status | | :--- | :--- | :---: | | TypeScript Support | Includes full type definitions for robust development. | ✅ | | Automatic Retry | Built-in mechanism with exponential backoff for reliability. | ✅ | | HTML Support | Capability to send rich-text emails using HTML bodies. | ✅ | | CC & BCC | Support for Carbon Copy and Blind Carbon Copy recipients. | ✅ | | Attachments | Support for sending files via AzureEmailAttachment. | ✅ | | Custom Sender | Option to define a specific display name for the "From" field. | ✅ | | Reply-to | Ability to specify a separate address for user responses. | ✅ | | Promise-based | Modern async/await API for clean asynchronous flow. | ✅ |

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues and questions, please open an issue on GitHub.