feat: support for stream transport for debug purposes

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-06-13 14:05:27 +03:00
parent ee9e1737b3
commit cdb630d9d8
6 changed files with 35 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend-module-email': patch
---
Add support for stream transport for debugging purposes
@@ -2,7 +2,7 @@
Adds support for sending Backstage notifications as emails to users.
Supports sending emails using `SMTP`, `SES`, or `sendmail`.
Supports sending emails using `SMTP`, `SES`, `sendmail`, or `stream` (for debugging purposes).
## Customizing email content
@@ -79,6 +79,10 @@ export interface Config {
* Newline style, defaults to 'unix'
*/
newline?: 'unix' | 'windows';
}
| {
/** Only for debugging, disables the actual sending of emails */
transport: 'stream';
};
/**
* Sender email address
@@ -38,6 +38,7 @@ import {
createSendmailTransport,
createSesTransport,
createSmtpTransport,
createStreamTransport,
} from './transports';
import { UserEntity } from '@backstage/catalog-model';
import { compact } from 'lodash';
@@ -129,6 +130,8 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
);
} else if (transport === 'sendmail') {
this.transporter = createSendmailTransport(this.transportConfig);
} else if (transport === 'stream') {
this.transporter = createStreamTransport();
} else {
throw new Error(`Unsupported transport: ${transport}`);
}
@@ -229,6 +232,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
private async sendMail(options: Mail.Options) {
try {
this.logger.debug(`Sending notification email to ${options.to}`);
await this.transporter.sendMail(options);
} catch (e) {
this.logger.error(`Failed to send email to ${options.to}: ${e}`);
@@ -16,3 +16,4 @@
export { createSmtpTransport } from './smtp';
export { createSesTransport } from './ses';
export { createSendmailTransport } from './sendmail';
export { createStreamTransport } from './stream';
@@ -0,0 +1,20 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createTransport } from 'nodemailer';
export const createStreamTransport = () => {
return createTransport({ streamTransport: true });
};