Socket
Book a DemoInstallSign in
Socket

@swiftpost/mail

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swiftpost/mail

Allows you to compose and send swift html emails, with a special focus on authentication emails.

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
 
Created
Source

@swiftpost/mail

SwiftPost

Overview

Allows you to compose and send swift html emails, with a special focus on authentication emails. It provides a flexible template system and integrates with Nodemailer for email delivery.

SwiftPost

Installation

npm install @swiftpost/mail

Usage

Configuration

Configure SwiftPost with your SMTP settings.

By default, it will use the environment variables SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USER, and SMTP_PASS to configure the SMTP connection. If SMTP_URL is set in the environment, it will be used instead. If SMTP_FROM is set, it will be used as the default sender email address.

import { SwiftPost } from "@swiftpost/mail";

const swiftPost = new SwiftPost({
  host: "smtp.swiftpost.io",
  port: 587,
  secure: false,
  auth: {
    user: "user@swiftpost.io",
    pass: "password",
  },
  from: "no-reply@swiftpost.io",
});

Sending Emails

Use the provided methods to send different types of emails.

await swiftPost.sendWelcomeEmail(
  { to: "hi@swiftpost.io" },
  {
    name: "Jon Manga",
    companyName: "SwiftPost",
    link: "https://swiftpost.io/welcome",
  }
);

SwiftPost methods

MethodDescription
sendWelcomeEmailGenerates and sends a welcome email.
getWelcomeEmailHtmlRenders and returns the html for a welcome email.
sendConfirmationEmailGenerates and sends a confirmation email.
getConfirmationEmailHtmlRenders and returns the html for a confirmation email.
sendPasswordResetEmailGenerates and sends a password reset email.
getPasswordResetEmailHtmlRenders and returns the html for a password reset email.
sendPasswordlessLoginEmailGenerates and sends a passwordless login email.
getPasswordlessLoginEmailHtmlRenders and returns the html for a passwordless login email.
sendAcceptInvitationEmailGenerates and sends an accept invitation email.
getAcceptInvitationEmailHtmlRenders and returns the html for an accept invitation email.
sendPasswordInvitationEmailGenerates and sends a password invitation email.
getPasswordInvitationEmailHtmlRenders and returns the html for a password invitation email.
sendWelcomeWithCredentialsEmailGenerates and sends a welcome with credentials email.
getWelcomeWithCredentialsEmailHtmlRenders and returns the html for a welcome with credentials email.
sendMailSends an email using nodemailer's sendMail method.

SwiftPost Options

SwiftPost options extend the Nodemailer SMTP options.

OptionTypeDescription
hoststringThe hostname or IP address to connect to (e.g., "smtp.swiftpost.io").
portnumberThe port to connect to (e.g., 587).
securebooleanIf true, the connection will use TLS when connecting to the server.
authobjectAuthentication object containing user and pass properties.
fromstringThe default email address to use as the sender.
urlstringSMTP URL to connect to.
transportobjectCustom transport object or string.
templatesDirstringDirectory path for email templates. You can specify your own path is you want to override the templates
debugbooleanIf true, enables debug mode for logging.

You also have access to the @swiftpost/templ package to use and render your own templates.

Example of a custom template:

const templatePath = path.join(__dirname, "templates", "my-template.html");
const html = await swiftPost.templ.render(templatePath, {
  name: "Jon Manga",
});
const template = `<h1>Hello {{ name }}</h1>`;
const html = await swiftPost.templ.render(template, {
  name: "Jon Manga",
});
await swiftPost.sendMail({
  to: "hi@swiftpost.io",
  subject: "My Template",
  html,
});

You can also have access to the Templ class directly to use your own templates.

const templ = new Templ({
  baseDir: path.join(__dirname, "templates"),
});

NestJS

See the @swiftpost/nest package for more information on how to use SwiftPost with NestJS.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Keywords

email

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts