12 Commits

Author SHA1 Message Date
91d271d4d6 3.0.0 2022-08-07 16:37:20 +02:00
bf6d9ad777 BREAKING CHANGE(core): switch to esm 2022-08-07 16:37:19 +02:00
8eafd81c9f 2.0.0 2021-06-15 17:31:02 +02:00
2b4024b535 BREAKING CHANGE(smartsmtp): now supports sending mails with sendmail 2021-06-15 17:31:01 +02:00
c018435aa1 1.0.8 2020-08-15 12:58:55 +00:00
b2eb8a2f59 fix(core): update 2020-08-15 12:58:54 +00:00
9e44474348 1.0.7 2020-08-15 12:58:02 +00:00
0c44743d99 fix(core): update 2020-08-15 12:58:01 +00:00
c9fd14df8b 1.0.6 2020-08-12 16:37:02 +00:00
2a2c7d3423 fix(core): update 2020-08-12 16:37:01 +00:00
10c316c324 1.0.5 2020-08-12 16:07:28 +00:00
93e926791a fix(core): update 2020-08-12 16:07:27 +00:00
11 changed files with 12802 additions and 8652 deletions

View File

@ -26,16 +26,28 @@ mirror:
- docker
- 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
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- 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:
- docker
allow_failure: true
# ====================
# test stage

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"args": [
"${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"
"type": "node-terminal"
}
]
}

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartsmtp",
"shortDescription": "a module for handling smtp stuff",
"description": "a module for handling smtp stuff",
"npmPackagename": "@pushrocks/smartsmtp",
"license": "MIT",
"projectDomain": "push.rocks"

21221
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +1,28 @@
{
"name": "@pushrocks/smartsmtp",
"version": "1.0.4",
"version": "3.0.0",
"private": false,
"description": "a module for handling smtp stuff",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tstest": "^1.0.73",
"@pushrocks/qenv": "^5.0.2",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.4"
},
"dependencies": {
"@pushrocks/smartmail": "^1.0.18",
"@types/nodemailer": "^6.4.0",
"nodemailer": "^6.4.11"
"@types/nodemailer": "^6.4.5",
"nodemailer": "^6.7.7"
},
"browserslist": [
"last 1 chrome versions"

View File

@ -1,5 +1,5 @@
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 * as smartmail from '@pushrocks/smartmail';
@ -9,15 +9,15 @@ const testQenv = new Qenv('./', './.nogit');
let testSmartsmtp: smartsmtp.Smartsmtp;
tap.test('should create a valid instance of Smartsmtp', async () => {
testSmartsmtp = new smartsmtp.Smartsmtp({
testSmartsmtp = await smartsmtp.Smartsmtp.createSmartsmtpWithRelay({
smtpServer: testQenv.getEnvVarOnDemand('SMTP_SERVER'),
smtpUser: testQenv.getEnvVarOnDemand('SMTP_USER'),
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(
new smartmail.Smartmail({
body: '',
@ -29,4 +29,17 @@ tap.test('should send a message', async () => {
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();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartsmtp',
version: '3.0.0',
description: 'a module for handling smtp stuff'
}

View File

@ -1,44 +1 @@
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 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;
}
}
export * from './smartsmtp.classes.smartsmtp.js';

View 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
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

@ -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"
}