Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
946e862b1c | |||
157bf6a893 | |||
5d5e2076d8 | |||
815b455dbb | |||
9d5907a7a7 | |||
0212d476c2 |
117
package-lock.json
generated
117
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/mailgun",
|
||||
"version": "1.0.15",
|
||||
"version": "1.0.18",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -199,23 +199,23 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smarthash": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.0.6.tgz",
|
||||
"integrity": "sha512-jHk9srgRLkszk/oPCUOkxTX2Fqu7qKwx13aEeSIBx8UCtFbXPLecJAqEaGEVk1mw9e4Oq0iC6O0jEnxKo5NQwA==",
|
||||
"version": "2.1.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.1.6.tgz",
|
||||
"integrity": "sha512-TYa3wECYkeDoE8SomxcCJFg5Kt4+G4MtNMu3yATJCCoPLJIbyV1CwUvYuFYkkce2W4ZvH9h/N6dsHc69oI5Jcw==",
|
||||
"requires": {
|
||||
"@pushrocks/smartjson": "^3.0.5",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartjson": "^3.0.10",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@types/through2": "^2.0.34",
|
||||
"through2": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartjson": {
|
||||
"version": "3.0.8",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.8.tgz",
|
||||
"integrity": "sha512-EjC3611RSZaZmK+nXxXrYDBxdxYWtrxjOrZtQzbYn0yM33KSCH0sLIAG8B2wYZVAOj4A2pC8mVxFSJ1w3iRFHg==",
|
||||
"version": "3.0.10",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.10.tgz",
|
||||
"integrity": "sha512-0tBkET2yjmSSIf4DlgeyU8U/J2EshTmQGuMY28EjPq9VvuCFXLh72WmETpA4QqKRMqhWp1+P+RZgnQupW3GQxQ==",
|
||||
"requires": {
|
||||
"@types/fast-json-stable-stringify": "^2.0.0",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"fast-json-stable-stringify": "^2.1.0",
|
||||
"lodash.clonedeep": "^4.5.0"
|
||||
}
|
||||
},
|
||||
@ -248,20 +248,20 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartmail": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.6.tgz",
|
||||
"integrity": "sha512-dQZi8FOLVfX6qo7b73HQ5SgdMHpS1mHNJTbwpgVT/XlhVCdreXfrAbFLVXECH4EZ8WYt9KoSUo4zHSw31g97sw==",
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmail/-/smartmail-1.0.8.tgz",
|
||||
"integrity": "sha512-ILUmtrJ0TlBe183/LXmJYAq268NueB6A0vA75qqR9+DeZjBAuYOcIAJxLOXyxtMcG/pSnr+AKTDBzsRn/RMz1g==",
|
||||
"requires": {
|
||||
"@pushrocks/smartfile": "^7.0.6",
|
||||
"@pushrocks/smartmustache": "^2.0.8"
|
||||
"@pushrocks/smartmustache": "^2.0.9"
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartmustache": {
|
||||
"version": "2.0.8",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmustache/-/smartmustache-2.0.8.tgz",
|
||||
"integrity": "sha512-bnOST5zKPKSpCUiYqSHRdJ4NpO3/xz3LLtNE+xfWLS9Eyor/dIapqOpqwmZXNYr8QZuZWC//dlTIiQcv02D8Rg==",
|
||||
"version": "2.0.9",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartmustache/-/smartmustache-2.0.9.tgz",
|
||||
"integrity": "sha512-Wumikw03se8/hpPDyBUt0o/JynkNLhuv667jUYyXmTbs4DLnlRAwTpLTYDUoaJpNWsCN3Jg9AgVSrteRozbFig==",
|
||||
"requires": {
|
||||
"handlebars": "^4.4.5"
|
||||
"handlebars": "^4.7.1"
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartparam": {
|
||||
@ -294,9 +294,9 @@
|
||||
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
|
||||
},
|
||||
"@pushrocks/smartrequest": {
|
||||
"version": "1.1.41",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.41.tgz",
|
||||
"integrity": "sha512-Kv2HXydJ3epFDEgfXm1RMLMQC6ix3sin8Gb3MioBWStqH3Aik6XvwNqPnBX5MBcVcbFOWQooJjjBRHM5k/hRXA==",
|
||||
"version": "1.1.47",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.47.tgz",
|
||||
"integrity": "sha512-0AuqtAI14VeWeXl2WpJbgCybVlG03rOjdGchAqy5k5lg9ACLhN3Z4kmoLgpBysWO/L2SjlAKB489SRyV3acykg==",
|
||||
"requires": {
|
||||
"@pushrocks/smartpromise": "^3.0.5",
|
||||
"@types/form-data": "^2.5.0",
|
||||
@ -330,9 +330,9 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartstring": {
|
||||
"version": "3.0.14",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.14.tgz",
|
||||
"integrity": "sha512-hN3IwTb5VBUis8Z5U5U6dDCnap6zBmkc9/IVx8lxAbsxl5TYQ4RiYlJ2JM4tih7EdE80ZeSdpprzChYrWmSwDg==",
|
||||
"version": "3.0.17",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.17.tgz",
|
||||
"integrity": "sha512-60JQptpgw+PjxoC5Gx+Y9m3/dtMstHC5ElpdJhIlbJ7dQV7LkCGSonLAG+NZhPbvrhow2KZ3fob8stW0Iuy3JQ==",
|
||||
"requires": {
|
||||
"crypto-random-string": "^3.0.1",
|
||||
"js-base64": "^2.5.1",
|
||||
@ -355,21 +355,22 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/tapbundle": {
|
||||
"version": "3.0.13",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz",
|
||||
"integrity": "sha512-23O4UMBafCuD+RnUlXNvtT9DGbL1HMD+xZE1Zcr7Ll7WvgxUgRQQfk9kq6qbLLbjaRe1J2Ijsgh1HuZbBaucLQ==",
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.0.tgz",
|
||||
"integrity": "sha512-xnKIGe7NJqxWBaFeKIEXShDjV2wap1XJqmlp3m1MKqmIF62vRpZnkzpyE1ZAoNwiYQmIsXIpvP/PDv+iPevPfw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@pushrocks/early": "^3.0.3",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smartfile": "^7.0.6",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"smartchai": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"@types/chai": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.4.tgz",
|
||||
"integrity": "sha512-7qvf9F9tMTzo0akeswHPGqgUx/gIaJqrOEET/FCD8CFRkSUHlygQiM5yB6OvjrtdxBVLSyw7COJubsFYs0683g==",
|
||||
"version": "4.2.7",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.7.tgz",
|
||||
"integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/chai-as-promised": {
|
||||
@ -443,9 +444,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.11.7",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.11.7.tgz",
|
||||
"integrity": "sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA=="
|
||||
"version": "13.1.6",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-13.1.6.tgz",
|
||||
"integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg=="
|
||||
},
|
||||
"@types/through2": {
|
||||
"version": "2.0.34",
|
||||
@ -792,9 +793,9 @@
|
||||
}
|
||||
},
|
||||
"fast-json-stable-stringify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://verdaccio.lossless.one/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
||||
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://verdaccio.lossless.one/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
|
||||
},
|
||||
"figures": {
|
||||
"version": "3.1.0",
|
||||
@ -874,14 +875,14 @@
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.2.tgz",
|
||||
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q=="
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.3.tgz",
|
||||
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
|
||||
},
|
||||
"handlebars": {
|
||||
"version": "4.4.5",
|
||||
"resolved": "https://verdaccio.lossless.one/handlebars/-/handlebars-4.4.5.tgz",
|
||||
"integrity": "sha512-0Ce31oWVB7YidkaTq33ZxEbN+UDxMMgThvCe8ptgQViymL5DPis9uLdTA13MiRPhgvqyxIegugrP97iK3JeBHg==",
|
||||
"version": "4.7.1",
|
||||
"resolved": "https://verdaccio.lossless.one/handlebars/-/handlebars-4.7.1.tgz",
|
||||
"integrity": "sha512-2dd6soo60cwKNJ90VewNLIzdZPR/E2YhszOTgHpN9V0YuwZk7x33/iZoIBnASwDFVHMY7iJ6NPL8d9f/DWYCTA==",
|
||||
"requires": {
|
||||
"neo-async": "^2.6.0",
|
||||
"optimist": "^0.6.1",
|
||||
@ -1056,16 +1057,16 @@
|
||||
}
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.40.0",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.40.0.tgz",
|
||||
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
|
||||
"version": "1.43.0",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-db/-/mime-db-1.43.0.tgz",
|
||||
"integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.24",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.24.tgz",
|
||||
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
|
||||
"version": "2.1.26",
|
||||
"resolved": "https://verdaccio.lossless.one/mime-types/-/mime-types-2.1.26.tgz",
|
||||
"integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==",
|
||||
"requires": {
|
||||
"mime-db": "1.40.0"
|
||||
"mime-db": "1.43.0"
|
||||
}
|
||||
},
|
||||
"mimic-fn": {
|
||||
@ -1342,9 +1343,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"resolve": {
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz",
|
||||
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
|
||||
"version": "1.14.2",
|
||||
"resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.14.2.tgz",
|
||||
"integrity": "sha512-EjlOBLBO1kxsUxsKjLt7TAECyKW6fOh1VRkykQkKGzcBbjjPIxBqGh0jf7GJ3k/f5mxMqW3htMD3WdTUVtW8HQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"path-parse": "^1.0.6"
|
||||
@ -1525,9 +1526,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"tslint": {
|
||||
"version": "5.20.0",
|
||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
|
||||
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
|
||||
"version": "5.20.1",
|
||||
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.1.tgz",
|
||||
"integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
@ -1578,9 +1579,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.6.4",
|
||||
"resolved": "https://verdaccio.lossless.one/uglify-js/-/uglify-js-3.6.4.tgz",
|
||||
"integrity": "sha512-9Yc2i881pF4BPGhjteCXQNaXx1DCwm3dtOyBaG2hitHjLWOczw/ki8vD1bqyT3u6K0Ms/FpCShkmfg+FtlOfYA==",
|
||||
"version": "3.7.5",
|
||||
"resolved": "https://verdaccio.lossless.one/uglify-js/-/uglify-js-3.7.5.tgz",
|
||||
"integrity": "sha512-GFZ3EXRptKGvb/C1Sq6nO1iI7AGcjyqmIyOw0DrD0675e+NNbGO72xmMM2iEBdFbxaTLo70NbjM/Wy54uZIlsg==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"commander": "~2.20.3",
|
||||
|
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mojoio/mailgun",
|
||||
"version": "1.0.15",
|
||||
"version": "1.0.18",
|
||||
"private": false,
|
||||
"description": "an api abstraction package for mailgun",
|
||||
"main": "dist/index.js",
|
||||
@ -16,15 +16,16 @@
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/qenv": "^4.0.6",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^12.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^13.1.6",
|
||||
"tslint": "^5.20.1",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartmail": "^1.0.6",
|
||||
"@pushrocks/smartrequest": "^1.1.41",
|
||||
"@pushrocks/smartstring": "^3.0.14"
|
||||
"@pushrocks/smartfile": "^7.0.6",
|
||||
"@pushrocks/smartmail": "^1.0.8",
|
||||
"@pushrocks/smartrequest": "^1.1.47",
|
||||
"@pushrocks/smartstring": "^3.0.17"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -28,4 +28,11 @@ tap.test('should send a smartmail', async () => {
|
||||
testMailgunAccount.sendSmartMail(testSmartmail, 'sandbox@mail.git.zone');
|
||||
});
|
||||
|
||||
tap.test('should retrieve a mail using a retrieval url', async () => {
|
||||
const result = await testMailgunAccount.retrieveSmartMailFromMessageUrl('https://sw.api.mailgun.net/v3/domains/mail.lossless.one/messages/AgMFnnnAKC8xp_dDa79LyoxhloxtaVmnRA==');
|
||||
result.options.subject = 'hi there. This is a testmail with attachment';
|
||||
result.options.from = 'noreply@mail.lossless.com';
|
||||
testMailgunAccount.sendSmartMail(result, 'sandbox@mail.git.zone');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1 +1,2 @@
|
||||
export * from './mailgun.classes.account';
|
||||
export * from './interfaces';
|
||||
|
2
ts/interfaces/index.ts
Normal file
2
ts/interfaces/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './message';
|
||||
export * from './notification';
|
30
ts/interfaces/message.ts
Normal file
30
ts/interfaces/message.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export interface IMailgunMessage {
|
||||
Received: string;
|
||||
From: string;
|
||||
'X-Envelope-From': string;
|
||||
recipients: string;
|
||||
'X-Google-Dkim-Signature': string;
|
||||
To: string;
|
||||
'message-headers': [[string, string]];
|
||||
'Dkim-Signature': string;
|
||||
'content-id-map': any;
|
||||
subject: 'test2';
|
||||
'stripped-html': string;
|
||||
'X-Mailgun-Incoming': 'Yes';
|
||||
'X-Received': string;
|
||||
'X-Gm-Message-State': string;
|
||||
'body-plain': string;
|
||||
attachments: Array<{
|
||||
url: string,
|
||||
'content-type': string,
|
||||
name: string,
|
||||
size: number
|
||||
}>;
|
||||
'body-html': string;
|
||||
'Mime-Version': string;
|
||||
Date: string,
|
||||
'Message-Id': string;
|
||||
'Content-Type': string;
|
||||
'X-Google-Smtp-Source': string;
|
||||
Subject: string;
|
||||
}
|
44
ts/interfaces/notification.ts
Normal file
44
ts/interfaces/notification.ts
Normal file
@ -0,0 +1,44 @@
|
||||
export interface IMailgunNotification {
|
||||
timestamp: string;
|
||||
token: string;
|
||||
signature: string;
|
||||
domain: string;
|
||||
'Received-Spf': string;
|
||||
From: string;
|
||||
'Return-Path': string;
|
||||
'Arc-Seal': string[],
|
||||
'Delivered-To': string;
|
||||
'X-Google-Dkim-Signature': string;
|
||||
To: string;
|
||||
'Dkim-Signature': string;
|
||||
subject: 'Booking confirmation (Order 12PN8P)';
|
||||
from: 'buchungsbestaetigung@bahn.de';
|
||||
'X-Received': string[];
|
||||
'Ironport-Sdr': string;
|
||||
'Arc-Authentication-Results': string[];
|
||||
'Arc-Message-Signature': string[];
|
||||
Date: string;
|
||||
'Message-Id': string;
|
||||
'Mime-Version': string;
|
||||
Received: string[];
|
||||
'Authentication-Results': string[];
|
||||
'X-Ipas-Result': string;
|
||||
'message-url': string;
|
||||
'message-headers': string;
|
||||
'Reply-To': string;
|
||||
recipient: string;
|
||||
sender: string;
|
||||
'X-Mailgun-Incoming': string;
|
||||
'X-Forwarded-For': string;
|
||||
'X-Gm-Message-State': string;
|
||||
'X-Google-Smtp-Source': string;
|
||||
'X-Envelope-From': '<phil+caf_=invoiceinbox=mail.lossless.one@lossless.com>';
|
||||
'Content-Type': 'multipart/mixed; boundary="----=_Part_220882_156025801.1578848484963"';
|
||||
'X-Forwarded-To': 'invoiceinbox@mail.lossless.one';
|
||||
Subject: string;
|
||||
attachments: string;
|
||||
'body-plain': string;
|
||||
'stripped-text': string;
|
||||
'stripped-html': string;
|
||||
'stripped-signature': string;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import * as plugins from './mailgun.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
export class MailgunAccount {
|
||||
public baseUrl = 'https://api.mailgun.net/v3';
|
||||
@ -8,9 +9,12 @@ export class MailgunAccount {
|
||||
this.apiToken = apiTokenArg;
|
||||
}
|
||||
|
||||
public getRequest(routeArg: string) {
|
||||
const requestUrl = `${this.baseUrl}${routeArg}`; // TODO;
|
||||
const response = plugins.smartrequest.request(routeArg, {
|
||||
public async getRequest(routeArg: string, binaryArg: boolean = false) {
|
||||
let requestUrl = routeArg;
|
||||
const needsBaseUrlPrefix = !routeArg.startsWith('https://');
|
||||
needsBaseUrlPrefix ? requestUrl = `${this.baseUrl}${routeArg}` : null;
|
||||
console.log(requestUrl);
|
||||
const requestOptions: plugins.smartrequest.ISmartRequestOptions = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Basic ${plugins.smartstring.base64.encode(
|
||||
@ -18,7 +22,14 @@ export class MailgunAccount {
|
||||
)}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
};
|
||||
let response: plugins.smartrequest.IExtendedIncomingMessage;
|
||||
if (!binaryArg) {
|
||||
response = await plugins.smartrequest.request(requestUrl, requestOptions);
|
||||
} else {
|
||||
response = await plugins.smartrequest.getBinary(requestUrl, requestOptions);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public async postFormData(routeArg: string, formFields: plugins.smartrequest.IFormField[]) {
|
||||
@ -65,6 +76,8 @@ export class MailgunAccount {
|
||||
}
|
||||
];
|
||||
|
||||
console.log(smartmailArg.attachments);
|
||||
|
||||
for (const attachment of smartmailArg.attachments) {
|
||||
formFields.push({
|
||||
name: 'attachment',
|
||||
@ -78,7 +91,35 @@ export class MailgunAccount {
|
||||
if (response.statusCode === 200) {
|
||||
return response.body;
|
||||
} else {
|
||||
console.log(response.body);
|
||||
throw new Error('could not send email');
|
||||
}
|
||||
}
|
||||
|
||||
public async retrieveSmartMailFromMessageUrl(messageUrlArg: string) {
|
||||
const response = await this.getRequest(messageUrlArg);
|
||||
const responseBody: interfaces.IMailgunMessage = response.body;
|
||||
const smartmail = new plugins.smartmail.Smartmail({
|
||||
from: responseBody.From,
|
||||
body: responseBody["body-html"],
|
||||
subject: responseBody.Subject,
|
||||
});
|
||||
|
||||
// lets care about attachments
|
||||
for (const attachmentInfo of responseBody.attachments) {
|
||||
const attachmentName = attachmentInfo.name;
|
||||
const attachmentContents = await this.getRequest(attachmentInfo.url, true);
|
||||
smartmail.addAttachment(new plugins.smartfile.Smartfile({
|
||||
path: `./${attachmentName}`,
|
||||
base: `./${attachmentName}`,
|
||||
contentBuffer: attachmentContents.body
|
||||
}));
|
||||
}
|
||||
|
||||
return smartmail;
|
||||
}
|
||||
|
||||
public async retrieveSmartMailFromNotifyPayload(notifyPayloadArg: any) {
|
||||
return await this.retrieveSmartMailFromMessageUrl(notifyPayloadArg['message-url']);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartmail from '@pushrocks/smartmail';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
|
||||
export { smartmail, smartrequest, smartstring };
|
||||
export { smartfile, smartmail, smartrequest, smartstring };
|
||||
|
Reference in New Issue
Block a user