17 Commits

Author SHA1 Message Date
5586d9a744 update description 2024-05-29 14:16:17 +02:00
75e3aa33e6 update tsconfig 2024-04-14 18:19:48 +02:00
d94117a606 update tsconfig 2024-04-01 21:41:04 +02:00
59e85680f7 update npmextra.json: githost 2024-04-01 19:59:40 +02:00
6cceb84d6b update npmextra.json: githost 2024-03-30 21:48:41 +01:00
69f095044a 3.0.3 2022-08-07 18:25:49 +02:00
d1b577275f fix(core): update 2022-08-07 18:25:48 +02:00
426abc0678 3.0.2 2022-08-07 18:23:54 +02:00
3d282385f3 fix(core): update 2022-08-07 18:23:53 +02:00
afd6bb8479 3.0.1 2022-08-07 18:18:29 +02:00
6dce86480c fix(core): update 2022-08-07 18:18:28 +02:00
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
13 changed files with 11231 additions and 8895 deletions

View File

@ -12,20 +12,12 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
@ -36,6 +28,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
@ -96,10 +89,9 @@ codequality:
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -119,11 +111,10 @@ trigger:
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
- npmci command npm run buildDocs
tags:
- lossless
- docker

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

@ -2,17 +2,31 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartsmtp",
"shortDescription": "a module for handling smtp stuff",
"npmPackagename": "@pushrocks/smartsmtp",
"description": "A module for handling SMTP operations such as sending emails via SMTP or sendmail transport.",
"npmPackagename": "@push.rocks/smartsmtp",
"license": "MIT",
"projectDomain": "push.rocks"
"projectDomain": "push.rocks",
"keywords": [
"SMTP",
"email",
"nodemailer",
"sendmail",
"smartmail integration",
"TypeScript",
"email sending",
"email templates",
"programming"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

19700
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +1,29 @@
{
"name": "@pushrocks/smartsmtp",
"version": "1.0.7",
"name": "@push.rocks/smartsmtp",
"version": "3.0.3",
"private": false,
"description": "a module for handling smtp stuff",
"description": "A module for handling SMTP operations such as sending emails via SMTP or sendmail transport.",
"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)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^14.0.27",
"tslint": "^6.1.3",
"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"
"@pushrocks/smartmail": "^1.0.21",
"@types/nodemailer": "^6.4.5",
"nodemailer": "^6.7.7"
},
"browserslist": [
"last 1 chrome versions"
@ -39,5 +39,21 @@
"cli.js",
"npmextra.json",
"readme.md"
]
}
],
"keywords": [
"SMTP",
"email",
"nodemailer",
"sendmail",
"smartmail integration",
"TypeScript",
"email sending",
"email templates",
"programming"
],
"homepage": "https://code.foss.global/push.rocks/smartsmtp",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartsmtp.git"
}
}

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

122
readme.md
View File

@ -1,39 +1,107 @@
# @pushrocks/smartsmtp
# @push.rocks/smartsmtp
a module for handling smtp stuff
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartsmtp)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartsmtp)
* [github.com (source mirror)](https://github.com/pushrocks/smartsmtp)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsmtp/)
## Install
## Status for master
To install `@push.rocks/smartsmtp`, use the following command with npm:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartsmtp/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartsmtp/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartsmtp)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartsmtp)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartsmtp)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartsmtp)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartsmtp)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
```bash
npm install @push.rocks/smartsmtp --save
```
Ensure that you are installing the package in a project set up with TypeScript and support for ECMAScript modules, as the usage examples provided will rely on this configuration.
## Usage
Use TypeScript for best in class intellisense
`@push.rocks/smartsmtp` simplifies handling SMTP-based emailing in Node.js applications, offering a streamlined interface to create transporters and send emails using popular services like Nodemailer and enhancements for template-based emails via `@pushrocks/smartmail`. This guide walks you through setting up a `Smartsmtp` instance and sending emails.
## Contribution
### Setting Up
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
First, ensure you import the necessary classes from the module. Here's how you set up your imports using ESM syntax:
For further information read the linked docs at the top of this readme.
```typescript
import { Smartsmtp } from '@push.rocks/smartsmtp';
```
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
### Creating SMTP Transport
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
`@push.rocks/smartsmtp` provides two primary ways to set up an SMTP transporter: through direct SMTP server credentials or utilizing the local `sendmail` command.
#### SMTP Server Credentials
To connect to an SMTP server directly, you'll need the server address, username, and password. Here's how you can create a `Smartsmtp` instance using SMTP server credentials:
```typescript
// Define your SMTP configuration
const smtpOptions = {
smtpServer: 'smtp.example.com',
smtpUser: 'user@example.com',
smtpPassword: 'yourPassword'
};
// Async function to create and use a Smartsmtp instance
async function setupSmtp() {
const smtpInstance = await Smartsmtp.createSmartsmtpWithRelay(smtpOptions);
// smtpInstance is now ready to use
}
```
#### Using Sendmail
If you wish to use the local `sendmail` command, which is common in UNIX environments, you can create a `Smartsmtp` instance dedicated to that:
```typescript
async function setupSendmail() {
const sendmailInstance = await Smartsmtp.createSmartsmtpSendmail();
// sendmailInstance is now ready to use for sending emails
}
```
### Sending Emails
With a `Smartsmtp` instance ready, you can send emails. This requires creating a `Smartmail` instance (from the `@pushrocks/smartmail` package) that defines the email configuration, including subjects, recipients, and body content.
```typescript
import { Smartmail } from '@pushrocks/smartmail';
async function sendEmail(smtpInstance: Smartsmtp) {
// Create a Smartmail instance
const myEmail = new Smartmail({
from: 'me@example.com',
subject: 'Test Email',
body: 'This is a test email sent using @push.rocks/smartsmtp.'
});
// Use the smtpInstance to send the email
const result = await smtpInstance.sendSmartMail(myEmail, 'recipient@example.com');
console.log(result); // Check the result
}
```
In the example above, `Smartmail` is utilized to define the base content of the email being sent. The `sendSmartMail` method of `Smartsmtp` takes this email configuration, alongside recipient details, and performs the sending operation.
This completes the basic usage guide for `@push.rocks/smartsmtp`. With these steps, you can integrate straightforward SMTP email sending capabilities into your Node.js applications, leveraging modern TypeScript syntax and ESM modules. For further customization and advanced features, refer to the documentation of Nodemailer and `@pushrocks/smartmail`.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

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.3',
description: 'a module for handling smtp stuff'
}

View File

@ -1,54 +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: 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);
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;
}
}

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

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