Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite the library in typescript for Postal v2 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
dist
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4
}
43 changes: 0 additions & 43 deletions Client.js

This file was deleted.

14 changes: 0 additions & 14 deletions Message.js

This file was deleted.

101 changes: 50 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
# Postal for Node

This library helps you send e-mails through the open source mail delivery
platform, [Postal](https://github.com/atech/postal) in Node.
platform, [Postal](https://github.com/postalserver/postal) in Node.

## Installation

Install the library using [NPM](https://www.npmjs.com/):
Install the library using [NPM](https://www.npmjs.com/) or [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/):

```
$ npm install @atech/postal --save
$ npm install @atech/postal
$ yarn install @atech/postal
```

## Usage

Sending an email is very simple. Just follow the example below. Before you can
begin, you'll need to login to your installation's web interface and generate
new API credentials.
new API credentials. This package assumes you are on Postal v2.

```javascript
// Include the Postal library
var Postal = require('@atech/postal');

// Create a new Postal client using a server key generated using your
// installation's web interface
var client = new Postal.Client('https://postal.yourdomain.com', 'your-api-key');

// Create a new message
var message = new Postal.SendMessage(client);

// Add some recipients
message.to('[email protected]');
message.to('[email protected]');
message.cc('[email protected]');
message.bcc('[email protected]');

// Specify who the message should be from - this must be from a verified domain
// on your mail server
message.from('[email protected]');

// Set the subject
message.subject('Hi there!');

// Set the content for the e-mail
message.plainBody('Hello world!');
message.htmlBody('<p>Hello world!</p>');

// Add any custom headers
message.header('X-PHP-Test', 'value');

// Attach any files
message.attach('textmessage.txt', 'text/plain', 'Hello world!');

// Send the message and get the result
message.send()
.then(function (result) {
var recipients = result.recipients();
// Loop through each of the recipients to get the message ID
for (var email in recipients) {
var message = recipients[email];
console.log(message.id()); // Logs the message ID
console.log(message.token()); // Logs the message's token
}
}).catch(function (error) {
// Do something with the error
console.log(error.code);
console.log(error.message);
});
const Postal = require('@atech/postal').default; // CommonJS
// OR
import Postal from '@atech/postal' // ES6 import

// Create a new Postal client using a server key generated using your installation's web interface
const client = new Postal({
hostname: 'https://postal.yourdomain.com',
apiKey: 'your-api-key',
});

// This must be in an async function
try {
// Send a new message
const message = await client.sendMessage({
// Set the subject
subject: 'Hi there!',
// Specify who the message should be from - this must be from a verified domain on your mail server
from: '[email protected]',
// Add some recipients
to: ['[email protected]', '[email protected]'],
cc: ['[email protected]'],
bcc: ['[email protected]'],
// Set the content for the e-mail
plain_body: 'Hello world!',
html_body: '<p>Hello world!</p>',
// Add any custom headers
headers: {
'X-PHP-Test': 'value',
},
// Attach any files
attachments: [
{
content_type: 'text/plain',
data: Buffer.from('Hello world!').toString('base64'),
name: 'textmessage.txt',
},
],
});

// Do something with the returned data
console.log(message);
} catch (error) {
// Handle the error
console.log(error);
}
```
74 changes: 0 additions & 74 deletions SendMessage.js

This file was deleted.

28 changes: 0 additions & 28 deletions SendRawMessage.js

This file was deleted.

26 changes: 0 additions & 26 deletions SendResult.js

This file was deleted.

9 changes: 0 additions & 9 deletions index.js

This file was deleted.

Loading