Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
69f095044a | |||
d1b577275f | |||
426abc0678 | |||
3d282385f3 | |||
afd6bb8479 | |||
6dce86480c | |||
91d271d4d6 | |||
bf6d9ad777 | |||
8eafd81c9f | |||
2b4024b535 | |||
c018435aa1 | |||
b2eb8a2f59 | |||
9e44474348 | |||
0c44743d99 |
@ -12,20 +12,12 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
@ -36,6 +28,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
@ -96,10 +89,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +111,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartsmtp",
|
"gitrepo": "smartsmtp",
|
||||||
"shortDescription": "a module for handling smtp stuff",
|
"description": "a module for handling smtp stuff",
|
||||||
"npmPackagename": "@pushrocks/smartsmtp",
|
"npmPackagename": "@pushrocks/smartsmtp",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
|
19700
package-lock.json
generated
19700
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartsmtp",
|
"name": "@pushrocks/smartsmtp",
|
||||||
"version": "1.0.6",
|
"version": "3.0.3",
|
||||||
"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",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.65",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.73",
|
||||||
"@pushrocks/qenv": "^4.0.10",
|
"@pushrocks/qenv": "^5.0.2",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^18.6.4"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartmail": "^1.0.18",
|
"@pushrocks/smartmail": "^1.0.21",
|
||||||
"@types/nodemailer": "^6.4.0",
|
"@types/nodemailer": "^6.4.5",
|
||||||
"nodemailer": "^6.4.11"
|
"nodemailer": "^6.7.7"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
21
test/test.ts
21
test/test.ts
@ -1,5 +1,5 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartsmtp from '../ts/index';
|
import * as smartsmtp from '../ts/index.js';
|
||||||
|
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
import * as smartmail from '@pushrocks/smartmail';
|
import * as smartmail from '@pushrocks/smartmail';
|
||||||
@ -9,15 +9,15 @@ 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'),
|
||||||
});
|
});
|
||||||
expect(testSmartsmtp).to.be.instanceOf(smartsmtp.Smartsmtp);
|
expect(testSmartsmtp).toBeInstanceOf(smartsmtp.Smartsmtp);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message', async () => {
|
tap.test('should send a message with empty body', async () => {
|
||||||
const result = await testSmartsmtp.sendSmartMail(
|
const result = await testSmartsmtp.sendSmartMail(
|
||||||
new smartmail.Smartmail({
|
new smartmail.Smartmail({
|
||||||
body: '',
|
body: '',
|
||||||
@ -29,4 +29,17 @@ tap.test('should send a message', async () => {
|
|||||||
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();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartsmtp',
|
||||||
|
version: '3.0.3',
|
||||||
|
description: 'a module for handling smtp stuff'
|
||||||
|
}
|
45
ts/index.ts
45
ts/index.ts
@ -1,44 +1 @@
|
|||||||
import * as plugins from './smartsmtp.plugins';
|
export * from './smartsmtp.classes.smartsmtp.js';
|
||||||
|
|
||||||
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.js';
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user