Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
8eafd81c9f | |||
2b4024b535 | |||
c018435aa1 | |||
b2eb8a2f59 | |||
9e44474348 | |||
0c44743d99 | |||
c9fd14df8b | |||
2a2c7d3423 | |||
10c316c324 | |||
93e926791a | |||
e0f1f1d1ac | |||
74cabfa878 | |||
c0b4291392 | |||
290b09623f |
@ -26,16 +26,28 @@ mirror:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
|
21744
package-lock.json
generated
21744
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsmtp",
|
"name": "@pushrocks/smartsmtp",
|
||||||
"version": "1.0.2",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a module for handling smtp stuff",
|
"description": "a module for handling smtp stuff",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -9,16 +9,15 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web)"
|
||||||
"format": "(gitzone format)"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.0.22",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.44",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"@pushrocks/qenv": "^4.0.10",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^15.12.2",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
25
test/test.ts
25
test/test.ts
@ -9,7 +9,7 @@ const testQenv = new Qenv('./', './.nogit');
|
|||||||
let testSmartsmtp: smartsmtp.Smartsmtp;
|
let testSmartsmtp: smartsmtp.Smartsmtp;
|
||||||
|
|
||||||
tap.test('should create a valid instance of Smartsmtp', async () => {
|
tap.test('should create a valid instance of Smartsmtp', async () => {
|
||||||
testSmartsmtp = new smartsmtp.Smartsmtp({
|
testSmartsmtp = await smartsmtp.Smartsmtp.createSmartsmtpWithRelay({
|
||||||
smtpServer: testQenv.getEnvVarOnDemand('SMTP_SERVER'),
|
smtpServer: testQenv.getEnvVarOnDemand('SMTP_SERVER'),
|
||||||
smtpUser: testQenv.getEnvVarOnDemand('SMTP_USER'),
|
smtpUser: testQenv.getEnvVarOnDemand('SMTP_USER'),
|
||||||
smtpPassword: testQenv.getEnvVarOnDemand('SMTP_PASSWORD'),
|
smtpPassword: testQenv.getEnvVarOnDemand('SMTP_PASSWORD'),
|
||||||
@ -17,14 +17,29 @@ tap.test('should create a valid instance of Smartsmtp', async () => {
|
|||||||
expect(testSmartsmtp).to.be.instanceOf(smartsmtp.Smartsmtp);
|
expect(testSmartsmtp).to.be.instanceOf(smartsmtp.Smartsmtp);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should send a message with empty body', async () => {
|
||||||
tap.test('should send a message', async () => {
|
const result = await testSmartsmtp.sendSmartMail(
|
||||||
const result = await testSmartsmtp.sendSmartMail(new smartmail.Smartmail({
|
new smartmail.Smartmail({
|
||||||
body: '',
|
body: '',
|
||||||
from: 'smartsmtp@mail.lossless.one',
|
from: 'smartsmtp@mail.lossless.one',
|
||||||
subject: 'this is a test message',
|
subject: 'this is a test message',
|
||||||
}), 'sandbox@mail.git.zone');
|
}),
|
||||||
|
'sandbox@mail.git.zone'
|
||||||
|
);
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a direct smartsmtp transport', async () => {
|
||||||
|
const smartsmtpInstance = await smartsmtp.Smartsmtp.createSmartsmtpSendmail();
|
||||||
|
const result = await smartsmtpInstance.sendSmartMail(
|
||||||
|
new smartmail.Smartmail({
|
||||||
|
body: 'hi there',
|
||||||
|
from: 'phil@lossless.com',
|
||||||
|
subject: 'this is a sendmail test message',
|
||||||
|
}),
|
||||||
|
'phil@kunz.io'
|
||||||
|
);
|
||||||
|
console.log(result);
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
45
ts/index.ts
45
ts/index.ts
@ -1,44 +1 @@
|
|||||||
import * as plugins from './smartsmtp.plugins';
|
export * from './smartsmtp.classes.smartsmtp';
|
||||||
|
|
||||||
export interface ISmartSmtpOptions {
|
|
||||||
smtpServer: string;
|
|
||||||
smtpUser: string;
|
|
||||||
smtpPassword: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use it to send mails via smtp
|
|
||||||
*/
|
|
||||||
export class Smartsmtp {
|
|
||||||
public nodemailerTransport: plugins.nodemailer.Transporter;
|
|
||||||
constructor(optionsArg: ISmartSmtpOptions) {
|
|
||||||
this.nodemailerTransport = plugins.nodemailer.createTransport({
|
|
||||||
host: optionsArg.smtpServer,
|
|
||||||
port: 465,
|
|
||||||
secure: true, // upgrade later with STARTTLS
|
|
||||||
auth: {
|
|
||||||
user: optionsArg.smtpUser,
|
|
||||||
pass: optionsArg.smtpPassword
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sends a SmartMail
|
|
||||||
*/
|
|
||||||
public async sendSmartMail(
|
|
||||||
smartmailArg: plugins.smartmail.Smartmail<any>,
|
|
||||||
toArg: string,
|
|
||||||
dataArg = {}
|
|
||||||
) {
|
|
||||||
const message = {
|
|
||||||
from: smartmailArg.options.from,
|
|
||||||
to: toArg,
|
|
||||||
subject: smartmailArg.getSubject(dataArg),
|
|
||||||
text: smartmailArg.getBody(dataArg),
|
|
||||||
html: smartmailArg.getBody(dataArg)
|
|
||||||
};
|
|
||||||
const response = await this.nodemailerTransport.sendMail(message);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
69
ts/smartsmtp.classes.smartsmtp.ts
Normal file
69
ts/smartsmtp.classes.smartsmtp.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import * as plugins from './smartsmtp.plugins';
|
||||||
|
|
||||||
|
export interface ISmartSmtpOptions {
|
||||||
|
smtpServer: string;
|
||||||
|
smtpUser: string;
|
||||||
|
smtpPassword: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use it to send mails via smtp
|
||||||
|
*/
|
||||||
|
export class Smartsmtp {
|
||||||
|
public static async createSmartsmtpWithRelay(optionsArg: ISmartSmtpOptions) {
|
||||||
|
const nodemailerTransport = plugins.nodemailer.createTransport({
|
||||||
|
host: optionsArg.smtpServer,
|
||||||
|
port: 465,
|
||||||
|
secure: true, // upgrade later with STARTTLS
|
||||||
|
auth: {
|
||||||
|
user: optionsArg.smtpUser,
|
||||||
|
pass: optionsArg.smtpPassword,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return new Smartsmtp(nodemailerTransport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async createSmartsmtpSendmail() {
|
||||||
|
const nodemailerTransport = plugins.nodemailer.createTransport({
|
||||||
|
sendmail: true,
|
||||||
|
newline: 'unix'
|
||||||
|
});
|
||||||
|
return new Smartsmtp(nodemailerTransport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public nodemailerTransport: plugins.nodemailer.Transporter;
|
||||||
|
constructor(transporterArg: plugins.nodemailer.Transporter) {
|
||||||
|
this.nodemailerTransport = transporterArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends a SmartMail
|
||||||
|
*/
|
||||||
|
public async sendSmartMail(
|
||||||
|
smartmailArg: plugins.smartmail.Smartmail<any>,
|
||||||
|
toArg: string,
|
||||||
|
dataArg = {}
|
||||||
|
) {
|
||||||
|
const message: plugins.nodemailer.SendMailOptions = {
|
||||||
|
from: smartmailArg.options.from,
|
||||||
|
to: toArg,
|
||||||
|
subject: smartmailArg.getSubject(dataArg),
|
||||||
|
text: smartmailArg.getBody(dataArg),
|
||||||
|
html: smartmailArg.getBody(dataArg),
|
||||||
|
attachments: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// lets add attachments from smartmailArg
|
||||||
|
for (const attachment of smartmailArg.attachments) {
|
||||||
|
message.attachments.push({
|
||||||
|
filename: attachment.parsedPath.base,
|
||||||
|
content: attachment.contentBuffer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.nodemailerTransport.sendMail(message).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,9 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartmail from '@pushrocks/smartmail';
|
import * as smartmail from '@pushrocks/smartmail';
|
||||||
|
|
||||||
export {
|
export { smartmail };
|
||||||
smartmail
|
|
||||||
};
|
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as nodemailer from 'nodemailer';
|
import * as nodemailer from 'nodemailer';
|
||||||
|
|
||||||
export {
|
export { nodemailer };
|
||||||
nodemailer
|
|
||||||
};
|
|
||||||
|
Reference in New Issue
Block a user