Skip to content

Commit 64ed2d7

Browse files
committed
fix: correct smtp port for local and prod
1 parent 1e26e2f commit 64ed2d7

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

.devcontainer/.env.production.local.example

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ PORT=3000
33
FRONTEND_URL=http://localhost:3000
44

55
DATABASE_URL=postgresql://admin_pg:password@postgres:5432/express-hybrid-auth-api-local-prod-db
6+
# Use the Docker service name 'postgres' as the host because the app runs inside a container.
7+
# Port 5432 is the default PostgreSQL port inside the container.
8+
# From the host machine (local Node.js), you would connect to localhost:5433 because of the port mapping in docker-compose.yml.
69

710
GOOGLE_CLIENT_ID=
811
GOOGLE_CLIENT_SECRET=
@@ -14,11 +17,13 @@ GITHUB_CALLBACK_URL=http://localhost:3000/auth/github/callback
1417

1518
NODE_ENV=development
1619

17-
REDIS_PORT=6379
18-
REDIS_HOST=redis # using redis service name because the app will run in a container so localhost is not correct
20+
REDIS_PORT=6379
21+
REDIS_HOST=redis # Use the Docker service name 'redis' because the app runs inside a container.
22+
# 'localhost' would point to the container itself, not the Redis container.
1923

20-
SMTP_HOST=smtp4dev
21-
SMTP_PORT=2525
24+
SMTP_HOST=smtp4dev # Docker service name for smtp4dev container
25+
SMTP_PORT=25 # Container's SMTP port (25).
26+
# Use port 25 here because inside the container, Docker networking connects directly to smtp4dev's internal port.
2227

2328
SESSION_SECRET="QeWMItONAv+x6AmdOJ2D5O1h/d//DjO5bpmjz6O0AOnxfc7Q4OlHYeXxX2HE6l0N2zEMZTAYmmRc8Z50UAFPHA=="
2429
ACCESS_TOKEN_SECRET="F9HHTuGGzVhbzB6rMoTLRVlZu7RhsicD6iF00xDn5K4UIlHtkcecz1bMyDRaewfjTUqmoTH6UWN22Bf7qymGBg=="

.devcontainer/docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
image: rnwood/smtp4dev
4444
ports:
4545
- '5000:80' # Web UI
46-
- '2525:2525' # SMTP server
46+
- '2525:25' # SMTP server (Host 2525 -> Container 25 (SMTP))
4747
restart: unless-stopped
4848
environment:
4949
- Logging__LogLevel__Default=Information

.devcontainer/docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ services:
6464
image: rnwood/smtp4dev
6565
ports:
6666
- '5000:80'
67-
- '2525:2525'
67+
- '2525:25' # SMTP server (Host 2525 -> Container 25 (SMTP))
6868
restart: unless-stopped
6969
environment:
7070
- Logging__LogLevel__Default=Information

src/lib/mail-transporter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ export const transporter = nodemailer.createTransport({
1111
// pass: '',
1212
// },
1313
});
14+
15+
transporter.sendMail(
16+
{
17+
from: 'test@example.com',
18+
to: 'user@example.com',
19+
subject: 'SMTP test',
20+
text: 'Hello from smtp4dev!',
21+
},
22+
(err, info) => {
23+
if (err) console.error('Error:', err);
24+
else console.log('Sent:', info);
25+
}
26+
);

src/lib/mailer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TwoFactorDisabledEmail from '../../emails/templates/2fa-disabled-email.js
77
import PasswordResetEmail from '../../emails/templates/password-reset-email.js';
88
import GlobalConfig from '../config.js';
99
import { transporter } from './mail-transporter.js';
10+
import logger from './logger/logger.js';
1011

1112
export async function sendVerificationEmail({
1213
token,
@@ -19,6 +20,7 @@ export async function sendVerificationEmail({
1920
expiresInMinutes: number;
2021
t: (key: string, options?: any) => string;
2122
}) {
23+
console.log('I am here');
2224
const emailHtml = await render(
2325
<VerificationEmail
2426
verificationUrl={`${GlobalConfig.EMAIL_FRONTEND_BASE_URL}/verify?token=${token}`}
@@ -36,7 +38,14 @@ export async function sendVerificationEmail({
3638
html: emailHtml,
3739
};
3840

39-
await transporter.sendMail(options);
41+
try {
42+
console.log('I am here');
43+
await transporter.sendMail(options);
44+
} catch (error) {
45+
console.log('error', error);
46+
logger.error('Failed to send verification email', { error, userEmail });
47+
throw error;
48+
}
4049
}
4150

4251
export async function sendAccountActivationEmail({

0 commit comments

Comments
 (0)