Git Product home page Git Product logo

directus-extension-mailer's Introduction

Directus Mailer

Directus Mailer ๐Ÿ’ฌ

An endpoint for sending emails with the Directus Nodemailer service.

Installation

  • Download or fork the repository
  • Install the requirements
    npm install
  • Build the extension
    npm run build
  • Create a folder in your directus endpoints folder named Mailer or an alternate route name.
  • Move the index.js build file to your new folder directus/extensions/endpoints/Mailer/index.js
  • Configure your email client in your .env file @email config.
  • Start your Directus instance npx directus start

Authentication

Requests made by unauthenticated users will be rejected. Requests must be made with a cookie or bearer token unless guest sending is active.

Sending Notifications

An example POST request made to https://directusAppDomain/Mailer{or custom path}/ In this example we are sending a test message to two recipients.

{
  "subject": "How cool is Directus?",
  "to": ["[email protected]", "[email protected]"],
  "template": {
    "name": "default-template",
  }
}

Liquid Templating ๐Ÿ’ง

You can build custom email templates with Liquid.js and add them to your extensions/templates folder to reference them as templates in your POST request. @email templating

If you're unfamiliar with Liquid, data can be referenced in a template with this interpolation{{title}} @data variables

{
  "from": "[email protected]",
  "to": "*********@gmail.com",
  "subject": "This email was made with Handlebars",
	"template" : {
    "name": "alert",
    "data" : {
      "title": "Im a title!",
      "subtitle": "Im a subtitle!",
      "body": "Im the body!"
	  }
  }
}

Attachments ๐Ÿ“ฆ

To add attachments in your email notification, include an array of attachment objects. @attachments

{
  "subject": "How cool is Directus?",
  "to": "[email protected]",
  "template": {
    "name": "default-template",
  }
  "attachments": [
    {
        "name": "image.png",
        "path": "./public/images/image.png"
    },
    {
      "name": "image_2.png",
      "path": "./public/images/image_2.png"
    }
  ]
}

Directus File Attachments

You can also include Directus files as attachments with an array of reference IDs. If the current user has permissions to view the file, then it will be attached to the email notification.

Note: Reference IDs that do not exist or do not meet the access requirements will be ignored.

{
  "subject": "How cool is Directus?",
  "to": "[email protected]",
  "template": {
    "name": "default-template",
  },
  "files":  [
	  "c17d967b-b257-414d-ab92-41ae6d0784ed",
		"b507c26f-1333-4a8a-b8df-9731be74542e"
	]
}

You can include both attachments and Directus files in your email notification.

{
  "subject": "How cool is Directus?",
  "to": "[email protected]",
  "template": {
    "name": "default-template",
  },
  "files":  [
	  "c17d967b-b257-414d-ab92-41ae6d0784ed",
	  "b507c26f-1333-4a8a-b8df-9731be74542e"
  ],
  "attachments": [
    {
      "filename": "text1.txt",
      "content": "hello world!"
    }
  ]
}

Environment Variables

EMAIL_ALLOW_GUEST_SEND=false

Guest sending is intended for more convenient debugging with API clients, you should always set this to false when not debugging. ๐Ÿšจ

directus-extension-mailer's People

Contributors

ryntab avatar jorgekorgut avatar sillymonkey1925 avatar ymc-sise avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.