GithubHelp home page GithubHelp logo

killmenot / nodemailer-postmark-transport Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 12.0 740 KB

Postmark transport for Nodemailer

License: MIT License

JavaScript 99.47% Shell 0.53%
nodemailer postmark transport postmark-templates postmark-transport

nodemailer-postmark-transport's Introduction

nodemailer-postmark-transport

A Postmark transport for Nodemailer.

Build Status Coverage Status Dependency Status devDependencies Status peerDependencies Status npm version Known Vulnerabilities Codacy Badge

Requirements

version Node.js peerDependencies
6.x 18+ nodemailer >=6.x
5.x 12+ nodemailer >=4.x
4.x 10+ nodemailer >=4.x
3.x 8+ nodemailer >=4.x
2.x 6+ nodemailer >=4.x
>=1.3 <2 4+
<1.3 0.10+

Migrating from version 1.x

Please see CHANGELOG for more details.

Install

npm install nodemailer-postmark-transport

Examples

Quickstart

'use strict';

const nodemailer = require('nodemailer');
const postmarkTransport = require('nodemailer-postmark-transport');
const transport = nodemailer.createTransport(postmarkTransport({
  auth: {
    apiKey: 'key'
  }
}));
const mail = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello',
  text: 'Hello',
  html: '<h1>Hello</h1>'
};

// callback style
transport.sendMail(mail, function (err, info) {
  if (err) {
    console.error(err);
  } else {
    console.log(info);
  }
});

// async/await style
try {
  const info = await transport.sendMail(mail);
  console.log(info);
} catch (err) {
  console.error(err);
}

Using Postmark templates feature

Read about Postmark templates here: Special delivery: Postmark templates. Read more about template alias here: How do I use a template alias?

'use strict';

const nodemailer = require('nodemailer');
const postmarkTransport = require('nodemailer-postmark-transport');
const transport = nodemailer.createTransport(postmarkTransport({
  auth: {
    apiKey: 'key'
  }
}));

// using templateId
let mail = {
  from: '[email protected]',
  to: '[email protected]',
  templateId: 1234,
  templateModel: {
    foo: 'bar'
  }
};

// using templateAlias
let mail = {
  from: '[email protected]',
  to: '[email protected]',
  templateAlias: 'buzz',
  templateModel: {
    foo: 'bar'
  }
};

transport.sendMail(mail, function (err, info) {
  if (err) {
    console.error(err);
  } else {
    console.log(info);
  }
});

Using attachments

References to nodemailer attachments docs and Postmark attachments docs

'use strict';

const nodemailer = require('nodemailer');
const postmarkTransport = require('nodemailer-postmark-transport');
const transport = nodemailer.createTransport(postmarkTransport({
  auth: {
    apiKey: 'key'
  }
}));
const mail = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello',
  text: 'Hello, This email contains attachments',
  html: '<h1>Hello, This email contains attachments</h1>',
  attachments: [
    {
      path: 'data:text/plain;base64,aGVsbG8gd29ybGQ=',
      cid: 'cid:molo.txt'
    }
  ]
};

transport.sendMail(mail, function (err, info) {
  if (err) {
    console.error(err);
  } else {
    console.log(info);
  }
});

Access to Postmark.js client

You can find more details about Postmark.js in documentation here

'use strict';

const nodemailer = require('nodemailer');
const postmarkTransport = require('nodemailer-postmark-transport');
const transporter = postmarkTransport({
  auth: {
    apiKey: 'key'
  }
});
const transport = nodemailer.createTransport(transporter);

// transporter.client -> reference to Postmark.js client
// transport.mailer.transporter.client -> reference to Postmark.js client

Provide Postmark.js client with custom client options

Postmark.js library allows to specify configuration options for its server client. You can get more details about possible values here and default values here

'use strict';

const nodemailer = require('nodemailer');
const postmarkTransport = require('nodemailer-postmark-transport');
const transport = nodemailer.createTransport(postmarkTransport({
  auth: {
    apiKey: 'key'
  },
  postmarkOptions: {
    timeout: 60
  }
}));

Contributors

List of project's contributors!

License

The MIT License (MIT)

Copyright (c) Alexey Kucherenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

nodemailer-postmark-transport's People

Contributors

danielmcconville avatar gabrielstuff avatar killmenot avatar lvnilesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nodemailer-postmark-transport's Issues

Add support for templates?

Templates are really a very strong to use Postmark for me, any way we can incorporate that into this?

`sendEmailBatch` breaks the message order from Postmark

Hi,

The _requestFactory function splits the results from client calls into 2 arrays, accepted and rejected.

Although this is useful, it causes a problem when sending batch emails and trying to reconcile failed messages against the input payload. When a message fails, Postmark sends back the following JSON:

{
  "ErrorCode": 405,
  "Message": "details"
}

This does not contain any identifier to indicate the original message that failed. This is fine in single emails but a problem in batch emails where you may have both successes and failures.

Postmark docs say that the results will be ordered the same as the original messages and leaves it to the user to compare the input against the results to match up the responses with the original messages.

Unfortunately this order is lost in the following code of the _requestFactory:

      results.forEach((result) => {
        if (result.ErrorCode === 0) {
          accepted.push(result);
        } else {
          rejected.push(result);
        }
      });

      return callback(null, {
        messageId: (results[0] || {}).MessageID,
        accepted: accepted,
        rejected: rejected
      });

A simple fix would be to update the _requestFactory to return an extra field that contains the original results, e.g.:

  export interface SentMessageInfo {
    messageId?: string;
    accepted: Array<Models.MessageSendingResponse>;
    rejected: Array<Models.MessageSendingResponse>;
    originalResults: Array<Models.MessageSendingResponse>;
  }

Consumers can then access that array if they wish to match the input to the output. I need this code so will raise a PR.

sendEmailBatchWithTemplates support?

Are you planning to add support for sendEmailBatchWithTemplates?
I would like to use nodemailer for sending batch emails with templates. But as I see this package is not supporting this.

postmarkOptions implemented?

The readme mentions using postmarkOptions but I'm not seeing it anywhere in the library. I was hoping to be able to attach tags or metadata as per Postmark's API like so:

postmarkOptions: {
  Tag: "test-tag",
  Metadata: { "foo":"bar" }
}

Thanks for your time!

Add type definitions for using this package with TypeScript.

Please add the type definitions to the DefinitelyTyped repository:

I ran the following command in console but type definations were not found for this package:

npm i --save-dev @types/nodemailer-postmark-transport

In the mean time, how to use this package with the TypeScript?

I'm getting the compilation error: error TS7016: Could not find a declaration file for module 'nodemailer-postmark-transport'.

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.