Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mailgun.js

Package Overview
Dependencies
Maintainers
4
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailgun.js - npm Package Compare versions

Comparing version 3.5.7 to 3.5.8

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

### [3.5.8](https://github.com/mailgun/mailgun-js/compare/v3.5.7...v3.5.8) (2021-09-02)
### Features
* Update index.ts export to fix commonJs imports ([246c046](https://github.com/mailgun/mailgun-js/commits/246c046619c593e5f13abe1ff0414fe9c9524cf9))
### Other changes
* Add examples of sending files to the readme ([a922b35](https://github.com/mailgun/mailgun-js/commits/a922b3590a6afd02e15650a2d6acf7b43933bb49))
### [3.5.7](https://github.com/mailgun/mailgun-js/compare/v3.5.6...v3.5.7) (2021-08-16)

@@ -7,0 +19,0 @@

6

dist/index.d.ts

@@ -0,7 +1,9 @@

import Client from './lib/client';
import Options from './lib/interfaces/Options';
import IFormData from './lib/interfaces/IFormData';
export default class Mailgun {
declare class Mailgun {
private formData;
constructor(FormData: new (...args: any[]) => IFormData);
client(options: Options): any;
client(options: Options): Client;
}
export = Mailgun;

@@ -5,2 +5,2 @@ /*! MIT License © Sindre Sorhus */

/*! mailgun.js v3.5.6 */
/*! mailgun.js v3.5.7 */

@@ -5,3 +5,3 @@ import Client from './lib/client';

export default class Mailgun {
class Mailgun {
private formData: new () => IFormData

@@ -13,5 +13,7 @@

client(options: Options) : any {
client(options: Options) : Client {
return new Client(options, this.formData);
}
}
export = Mailgun;

@@ -23,9 +23,12 @@ const urljoin = require('url-join');

return pages.reduce(
(acc: any, [id, url]: [url: string, id: string]) => {
acc[id] = this._parsePage(id, url)
return acc
}, {});
(acc: any, entrie: [url: string, id: string]) => {
const id = entrie[0];
const url = entrie[1];
acc[id] = this._parsePage(id, url);
return acc;
}, {}
);
}
_parseEventList(response: { body: { items: any, paging: any } }) {
_parseEventList(response: { body: { items: any, paging: any } }) {
return {

@@ -32,0 +35,0 @@ items: response.body.items,

{
"name": "mailgun.js",
"version": "3.5.7",
"version": "3.5.8",
"main": "dist/mailgun.js",

@@ -22,2 +22,3 @@ "types": "dist/index.d.ts",

"build": "webpack --config ./webpack.config.js --progress --color",
"build:release": "webpack --config ./webpack.release.config.js --progress --color",
"start": "webpack --watch --config ./webpack.config.js --progress --color",

@@ -68,2 +69,3 @@ "release": "standard-version -a",

"standard-version": "^9.3.1",
"terser-webpack-plugin": "^5.2.0",
"ts-loader": "^8.0.12",

@@ -70,0 +72,0 @@ "ts-node": "^9.1.1",

@@ -14,3 +14,3 @@ # Mailgun.js [![Build Status](https://travis-ci.org/mailgun/mailgun-js.svg)](https://travis-ci.org/mailgun/mailgun-js)

- [Browser Demo](#browser-demo)
- [Examples](https://github.com/mailgun/mailgun-js/tree/c379f79ea2a2e0f825103751a3a102d8bdd3dd1b/example)
- [Examples](https://github.com/mailgun/mailgun-js/tree/master/examples)
- [Development](#development)

@@ -156,2 +156,120 @@ - [Requirements](#requirements)

Messages with attachments:
- Node.js example of send file as an attachment
```js
const fsPromises = require('fs').promises;
const path = require('path');
const filepath = path.resolve(__dirname, '../test.pdf');
let messageParams = {
from: "Excited User <mailgun@sandbox-123.mailgun.org>",
to: ["test@example.com"],
subject: "Test subject",
message: "Hello here is a file in the attachment"
}
fsPromises.readFile(filepath)
.then(data => {
const file = {
filename: 'test-rename.pdf',
data
}
messageParams.attachment = file;
return mg.messages.create('sandbox-123.mailgun.org', messageParams);
})
.then(response => {
console.log(response);
})
```
- Node.js example of send multiple files as an attachment
```js
const fsPromises = require('fs').promises;
const path = require('path');
const filepath = path.resolve(__dirname, '../test.pdf');
const filepath1 = path.resolve(__dirname, '../test.jpg');
let messageParams = {
from: "Excited User <mailgun@sandbox-123.mailgun.org>",
to: ["test@example.com"],
subject: "Test subject",
message: "Test message"
}
(async () =>{
try {
const firstFile = {
filename: 'test.pdf',
data: await fsPromises.readFile(filepath)
}
const secondFile = {
filename: 'test.jpg',
data: await fsPromises.readFile(filepath1)
}
messageParams.attachment = [firstFile, secondFile];
const result = await mg.messages.create('sandbox-123.mailgun.org', messageParams);
console.log(result);
} catch (error) {
console.error(error);
}
})()
```
- Node.js example of send file as inline image
```js
const fsPromises = require('fs').promises;
const path = require('path');
const filepath = path.resolve(__dirname, '../test.jpg');
let messageParams = {
from: "Excited User <mailgun@sandbox-123.mailgun.org>",
to: ["test@example.com"],
subject: "Test subject",
html: '<div><img alt="image" id="1" src="cid:test.jpg"/></div> Some extra text'
}
fsPromises.readFile(filepath)
.then(data => {
const file = {
filename: 'test.jpg',
data
}
messageParams.inline = file;
return mg.messages.create('sandbox-123.mailgun.org', messageParams);
})
.then(response => {
console.log(response);
})
```
- Browser example of send file
Before sending the file you need to somehow get the Blob of the file.
Usually can get it from the onChange event of input tag with type file.
```js
const handleFileSelected = async (event) => {
const files = Array.from(event.target.files)
const fileBuffer = await files[0];
}
<input type="file" onChange={handleFileSelected} name="file-uploader"/>
```
Then you can use the same approach as shown above for node.js apps.
```js
const file = {
filename: 'test.pdf',
data: fileBuffer
};
let messageParams = {
from: "Excited User <mailgun@sandbox-123.mailgun.org>",
to: ["test@example.com"],
subject: "Test subject",
text: "Hello here is a file in the attachment",
attachment: file
};
const res = await mg.messages.create(DOMAIN, messageParams);
```
Promise Returns:

@@ -158,0 +276,0 @@

@@ -14,2 +14,3 @@ {

"skipLibCheck": true
// "strict": true,
},

@@ -16,0 +17,0 @@ "typedocOptions": {

@@ -0,1 +1,2 @@

/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require('webpack');

@@ -21,3 +22,2 @@ const path = require('path');

library: 'mailgun',
libraryExport: 'default',
libraryTarget: 'umd',

@@ -24,0 +24,0 @@ globalObject: 'this',

@@ -0,6 +1,7 @@

/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const { merge } = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin');
const baseConfig = require('./webpack.config.js');
const TerserPlugin = require('terser-webpack-plugin');

@@ -7,0 +8,0 @@ module.exports = (env) => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc