mirror of
https://github.com/colanode/colanode.git
synced 2026-09-01 19:50:56 +02:00
Make SMTP service optional
This commit is contained in:
@@ -63,6 +63,7 @@ export interface SmtpConfiguration {
|
||||
port: number;
|
||||
user: string;
|
||||
password: string;
|
||||
secure: boolean;
|
||||
from: {
|
||||
email: string;
|
||||
name: string;
|
||||
@@ -200,6 +201,7 @@ export const configuration: Configuration = {
|
||||
smtp: {
|
||||
host: getOptionalEnv('SMTP_HOST') || '',
|
||||
port: parseInt(getOptionalEnv('SMTP_PORT') || '587'),
|
||||
secure: getOptionalEnv('SMTP_SECURE') === 'true',
|
||||
user: getOptionalEnv('SMTP_USER') || '',
|
||||
password: getOptionalEnv('SMTP_PASSWORD') || '',
|
||||
from: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import { createDebugger } from '@colanode/core';
|
||||
|
||||
import { configuration } from '@/lib/configuration';
|
||||
|
||||
@@ -9,6 +10,8 @@ interface EmailMessage {
|
||||
html?: string;
|
||||
}
|
||||
|
||||
const debug = createDebugger('server:service:email');
|
||||
|
||||
class EmailService {
|
||||
private transporter: nodemailer.Transporter | undefined;
|
||||
|
||||
@@ -23,13 +26,14 @@ class EmailService {
|
||||
!configuration.smtp.from.email ||
|
||||
!configuration.smtp.from.name
|
||||
) {
|
||||
throw new Error('SMTP configuration is missing');
|
||||
debug('SMTP configuration is not set, skipping initialization');
|
||||
return;
|
||||
}
|
||||
|
||||
this.transporter = nodemailer.createTransport({
|
||||
host: configuration.smtp.host,
|
||||
port: configuration.smtp.port,
|
||||
secure: true,
|
||||
secure: configuration.smtp.secure,
|
||||
auth: {
|
||||
user: configuration.smtp.user,
|
||||
pass: configuration.smtp.password,
|
||||
@@ -41,7 +45,8 @@ class EmailService {
|
||||
|
||||
public async sendEmail(message: EmailMessage): Promise<void> {
|
||||
if (!this.transporter) {
|
||||
throw new Error('Email service not initialized');
|
||||
debug('Email service not initialized, skipping email send');
|
||||
return;
|
||||
}
|
||||
|
||||
await this.transporter.sendMail({
|
||||
|
||||
Reference in New Issue
Block a user