Skip to content

Commit eaa038d

Browse files
committed
✨ feat: disable STARTTLS
1 parent a6b2002 commit eaa038d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/api/services/smtp.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { sendMessage } from './sendMessage';
66
// You can send an example mail with
77
// msmtp --host=localhost --port=3388 --auth=off --tls=off --from=sender@example.com admin@project.de < dev-example-mail.txt
88

9-
export const smtpServer = new SMTPServer({
9+
const smtpServer = new SMTPServer({
1010
authOptional: true,
11-
secure: false,
11+
disabledCommands: ['STARTTLS'],
1212
onData(stream, session, cb) {
1313
stream.on('end', () => cb(null));
1414
simpleParser(stream, async (err, parsed) => {
@@ -33,3 +33,11 @@ smtpServer.on('error', (err) => {
3333
smtpServer.listen(configPrivate.SMTP_PORT, configPrivate.SMTP_HOST);
3434

3535
console.info(`SMTP server listening on ${configPrivate.SMTP_HOST}:${configPrivate.SMTP_PORT}`);
36+
37+
smtpServer.on('close', () => {
38+
console.info('SMTP server closed');
39+
});
40+
41+
export function closeSMTPServer() {
42+
smtpServer.close();
43+
}

src/hooks.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { paraglideMiddleware } from '$lib/paraglide/server';
33
import { sequence } from '@sveltejs/kit/hooks';
44
import { OIDC } from '$api/services/OIDC';
55
import type { ServerInit } from '@sveltejs/kit';
6-
import { smtpServer } from '$api/services/smtp';
7-
import { dev } from '$app/environment';
6+
import { closeSMTPServer } from '$api/services/smtp';
87

98
export const handle: Handle = sequence(OIDC.handle, ({ event, resolve }) =>
109
paraglideMiddleware(event.request, ({ request: localizedRequest, locale }) => {
@@ -20,6 +19,6 @@ export const handle: Handle = sequence(OIDC.handle, ({ event, resolve }) =>
2019

2120
export const init: ServerInit = async () => {
2221
process.on('sveltekit:shutdown', async (reason) => {
23-
smtpServer.close();
22+
closeSMTPServer();
2423
});
2524
};

0 commit comments

Comments
 (0)