11import type { NotificationAgentEmail } from '@server/lib/settings' ;
22import { getSettings } from '@server/lib/settings' ;
33import Email from 'email-templates' ;
4+ import net from 'node:net' ;
45import nodemailer from 'nodemailer' ;
6+ import type SMTPTransport from 'nodemailer/lib/smtp-transport' ;
57import { URL } from 'url' ;
68import { openpgpEncrypt } from './openpgpEncrypt' ;
79
10+ const getSocket : SMTPTransport . Options [ 'getSocket' ] = ( options , callback ) => {
11+ const socket = net . connect ( {
12+ host : options . host ?? 'localhost' ,
13+ port : options . port ?? 587 ,
14+ localAddress : options . localAddress ,
15+ } ) ;
16+ const onError = ( error : Error ) => callback ( error , undefined ) ;
17+ const onConnect = ( ) => {
18+ socket . removeListener ( 'error' , onError ) ;
19+ callback ( null , { connection : socket } ) ;
20+ } ;
21+
22+ socket . once ( 'error' , onError ) ;
23+ socket . once ( 'connect' , onConnect ) ;
24+ } ;
25+
826class PreparedEmail extends Email {
927 public constructor ( settings : NotificationAgentEmail , pgpKey ?: string ) {
1028 const { applicationUrl } = getSettings ( ) . main ;
@@ -28,6 +46,7 @@ class PreparedEmail extends Email {
2846 pass : settings . options . authPass ,
2947 }
3048 : undefined ,
49+ getSocket : net . isIP ( settings . options . smtpHost ) ? undefined : getSocket ,
3150 } ) ;
3251
3352 if ( pgpKey ) {
0 commit comments