Skip to content

Commit 222ba06

Browse files
committed
More email service stuff
1 parent 6f1ee6b commit 222ba06

File tree

9 files changed

+714
-18
lines changed

9 files changed

+714
-18
lines changed

packages/api/src/services/newsletters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const createRandomEmailAddress = (userName: string, length: number): string => {
113113
when rand is sdfsdf-: [email protected]
114114
when rand is abcdef: [email protected]
115115
*/
116-
return `${userName}-${nanoid(length)}e@${inbox}.omnivore.app`
116+
return `${userName}-${nanoid(length)}e@${env.email.domain}`
117117
}
118118

119119
export const findNewsletterEmailById = async (

packages/api/src/util.ts

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export interface BackendEnv {
9898
useLocalStorage: boolean
9999
localMinioUrl: string
100100
}
101+
email: {
102+
domain: string
103+
}
101104
sender: {
102105
message: string
103106
feedback: string
@@ -206,6 +209,7 @@ const nullableEnvVars = [
206209
'INTERCOM_ANDROID_SECRET',
207210
'EXPORT_TASK_HANDLER_URL',
208211
'LOCAL_MINIO_URL',
212+
'LOCAL_EMAIL_DOMAIN',
209213
] // Allow some vars to be null/empty
210214

211215
const envParser =
@@ -245,6 +249,7 @@ export function getEnv(): BackendEnv {
245249
pool: {
246250
max: parseInt(parse('PG_POOL_MAX'), 10),
247251
},
252+
248253
replication: parse('PG_REPLICATION') === 'true',
249254
replica: {
250255
host: parse('PG_REPLICA_HOST'),
@@ -254,6 +259,9 @@ export function getEnv(): BackendEnv {
254259
dbName: parse('PG_REPLICA_DB'),
255260
},
256261
}
262+
const email = {
263+
domain: parse('LOCAL_EMAIL_DOMAIN'),
264+
}
257265
const server = {
258266
jwtSecret: parse('JWT_SECRET'),
259267
ssoJwtSecret: parse('SSO_JWT_SECRET'),
@@ -382,6 +390,7 @@ export function getEnv(): BackendEnv {
382390
return {
383391
pg,
384392
client,
393+
email,
385394
server,
386395
google,
387396
posthog,

packages/local-mail-watcher/src/env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface WatcherEnv {
1717

1818
const envParser =
1919
(env: { [key: string]: string | undefined }) =>
20-
(varName: string, throwOnUndefined = true): string | undefined => {
20+
(varName: string, throwOnUndefined = false): string | undefined => {
2121
const value = env[varName]
2222
if (typeof value === 'string' && value) {
2323
return value

packages/local-mail-watcher/src/watcher.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { sendToEmailApi } from './lib/emailApi'
55
import { env } from './env'
66

77
chokidar.watch(env.filesystem.filePath).on('add', (path, _event) => {
8-
// console.log(event, path)
8+
console.log(path)
99
const contents = fs.readFileSync(path).toString()
1010
simpleParser(contents)
1111
.then((it) => ({
@@ -16,6 +16,12 @@ chokidar.watch(env.filesystem.filePath).on('add', (path, _event) => {
1616
text: it.text || '',
1717
headers: it.headers,
1818
}))
19-
.then((emailData) => sendToEmailApi(emailData))
20-
.then(() => fs.unlinkSync(path))
19+
.then(async (emailData) => {
20+
await sendToEmailApi(emailData)
21+
console.log('Sent to email API')
22+
})
23+
.then(() => {
24+
fs.unlinkSync(path)
25+
console.log('Deleted File')
26+
})
2127
})

self-hosting/docker-compose/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ REDIS_URL=redis://redis:6379/0
3737

3838
#MAIL
3939
WATCHER_API_KEY=mail-api-key
40+
LOCAL_EMAIL_DOMAIN=domain.tld
4041

4142
# Web
4243
APP_ENV=prod

self-hosting/docker-compose/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ services:
144144
depends_on:
145145
- minio
146146
entrypoint: >
147-
/bin/sh -c "
147+
/bin/bash -c "
148148
sleep 5;
149149
until (/usr/bin/mc config host add myminio http://minio:9000 minio miniominio) do echo '...waiting...' && sleep 1; done;
150150
/usr/bin/mc mb myminio/omnivore;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#MAIL
22
WATCHER_API_KEY=mail-api-key
33
MAIL_FILE_PATH=/var/mail/domain.tld/user/new
4-
WATCHER_API_ENDPOINT=https://omnivore-watch.domain.com
4+
WATCHER_API_ENDPOINT=https://omnivore-watch.domain.tld

self-hosting/docker-compose/mail/docker-compose-mail.yml

+30-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
image: ghcr.io/docker-mailserver/docker-mailserver:latest
44
container_name: mailserver
55
# Provide the FQDN of your mail server here (Your DNS MX record should point to this value)
6-
hostname: mail.podginator.com
6+
hostname: mail.domain.tld
77
env_file: mailserver.env
88
# More information about the mail-server ports:
99
# https://docker-mailserver.github.io/docker-mailserver/latest/config/security/understanding-the-ports/
@@ -14,10 +14,11 @@ services:
1414
- "587:587" # ESMTP (explicit TLS => STARTTLS)
1515
- "993:993" # IMAP4 (implicit TLS)
1616
volumes:
17-
- mailserver:/var/mail/
18-
- mailserver:/var/mail-state/
19-
- mailserver:/var/log/mail/
20-
- mailserver:/tmp/docker-mailserver/
17+
- ./docker-data/dms/mail-data/:/var/mail/
18+
- ./docker-data/dms/mail-state/:/var/mail-state/
19+
- ./docker-data/dms/mail-logs/:/var/log/mail/
20+
- ./docker-data/dms/config/:/tmp/docker-mailserver/
21+
- /etc/localtime:/etc/localtime:ro
2122
restart: always
2223
stop_grace_period: 1m
2324
# Uncomment if using `ENABLE_FAIL2BAN=1`:
@@ -27,17 +28,35 @@ services:
2728
test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
2829
timeout: 3s
2930
retries: 0
30-
api:
31+
docker:
32+
image: docker:latest
33+
container_name: setup-email
34+
environment:
35+
- DOMAIN="domain.tld"
36+
volumes:
37+
- ./docker-data/dms/mail-data/:/var/mail/
38+
- /var/run/docker.sock:/var/run/docker.sock
39+
- ./docker-data/dms/config/:/tmp/docker-mailserver/
40+
depends_on:
41+
mailserver:
42+
condition: service_started
43+
tty: true
44+
entrypoint: >
45+
/bin/sh -c "
46+
sleep 5;
47+
docker exec -ti mailserver setup email add [email protected] pass123;
48+
echo '@domain.tld [email protected]' > /tmp/docker-mailserver/config/postfix-virtual.cf
49+
exit 0
50+
"
51+
watcher:
3152
build:
3253
context: ../../../
3354
dockerfile: ./packages/local-mail-watcher/Dockerfile-watcher
3455
container_name: "omnivore-mail-watch"
3556
volumes:
36-
- mailserver:/var/mail/
57+
- ./docker-data/dms/mail-data/:/var/mail/
3758
env_file:
3859
- .env.mail
3960
depends_on:
40-
mailserver:
41-
condition: service_started
42-
volumes:
43-
mailserver:
61+
docker:
62+
condition: service_completed_successfully

0 commit comments

Comments
 (0)