diff --git a/backend/src/middleware/helpers/email/sendMail.js b/backend/src/middleware/helpers/email/sendMail.js
index 9886b88e2..a1b3b238a 100644
--- a/backend/src/middleware/helpers/email/sendMail.js
+++ b/backend/src/middleware/helpers/email/sendMail.js
@@ -14,10 +14,12 @@ let sendMailCallback = async (templateArgs) => {
if (!hasEmailConfig) {
if (!CONFIG.TEST) {
// eslint-disable-next-line no-console
- console.log('Warning: Email middleware will not try to send mails.') // Wolle
+ console.log('Warning: Middlewares will not try to send mails.') // Wolle
}
} else {
sendMailCallback = async (templateArgs) => {
+ // Wolle
+ console.log('templateArgs: ', templateArgs)
const transporter = nodemailer.createTransport({
host: CONFIG.SMTP_HOST,
port: CONFIG.SMTP_PORT,
diff --git a/backend/src/middleware/helpers/email/templateBuilder.js b/backend/src/middleware/helpers/email/templateBuilder.js
index 9de26f48e..f37e89a4b 100644
--- a/backend/src/middleware/helpers/email/templateBuilder.js
+++ b/backend/src/middleware/helpers/email/templateBuilder.js
@@ -3,6 +3,8 @@ import CONFIG from '../../../config'
import logosWebapp from '../../../config/logos.js'
import * as templates from './templates'
+import * as templatesEN from './templates/en'
+import * as templatesDE from './templates/de'
const from = CONFIG.EMAIL_DEFAULT_SENDER
const welcomeImageUrl = new URL(logosWebapp.LOGO_WELCOME_PATH, CONFIG.CLIENT_URI)
@@ -90,3 +92,33 @@ export const wrongAccountTemplate = ({ email }) => {
),
}
}
+
+export const notificationTemplate = ({ email, notification }) => {
+ const subject = `${CONFIG.APPLICATION_NAME} – Benachrichtigung | Notification`
+ const actionUrl = new URL('/notifications', CONFIG.CLIENT_URI)
+ // TODO Wolle language
+ let content
+ switch (notification.to.locale) {
+ case 'de':
+ content = templatesDE.notification
+ break
+ case 'en':
+ content = templatesEN.notification
+ break
+
+ default:
+ content = templatesEN.notification
+ break
+ }
+
+ return {
+ from,
+ to: email,
+ subject,
+ html: mustache.render(
+ templates.layout,
+ { ...defaultParams, actionUrl, supportUrl: /* Wolle */ CONFIG.SUPPORT_URL, welcomeImageUrl },
+ { content },
+ ),
+ }
+}
diff --git a/backend/src/middleware/helpers/email/templates/de/index.js b/backend/src/middleware/helpers/email/templates/de/index.js
new file mode 100644
index 000000000..0f9d13c36
--- /dev/null
+++ b/backend/src/middleware/helpers/email/templates/de/index.js
@@ -0,0 +1,6 @@
+import fs from 'fs'
+import path from 'path'
+
+const readFile = (fileName) => fs.readFileSync(path.join(__dirname, fileName), 'utf-8')
+
+export const notification = readFile('./notification.html')
diff --git a/backend/src/middleware/helpers/email/templates/de/notification.html b/backend/src/middleware/helpers/email/templates/de/notification.html
new file mode 100644
index 000000000..cb566099e
--- /dev/null
+++ b/backend/src/middleware/helpers/email/templates/de/notification.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Hallo {{ name }}!
+ Du hast mindestens eine Banachrichtigung bekommen! Mit Klick auf diesen Button
+ kannst Du deine Nachrichten ansehen:
+ |
+
+
+ |
+
+
+
+ |
+
+ –––––––––––––––––––––––––––––––––––––––––––––––
+ |
+
+
+ |
+
+
+
+
+
diff --git a/backend/src/middleware/helpers/email/templates/en/index.js b/backend/src/middleware/helpers/email/templates/en/index.js
new file mode 100644
index 000000000..0f9d13c36
--- /dev/null
+++ b/backend/src/middleware/helpers/email/templates/en/index.js
@@ -0,0 +1,6 @@
+import fs from 'fs'
+import path from 'path'
+
+const readFile = (fileName) => fs.readFileSync(path.join(__dirname, fileName), 'utf-8')
+
+export const notification = readFile('./notification.html')
diff --git a/backend/src/middleware/helpers/email/templates/en/notification.html b/backend/src/middleware/helpers/email/templates/en/notification.html
new file mode 100644
index 000000000..d49538356
--- /dev/null
+++ b/backend/src/middleware/helpers/email/templates/en/notification.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Hello {{ name }}!
+ You have received at least one notification! By clicking on this button
+ you can view your messages:
+ |
+
+
+ |
+
+
+
+ |
+
+ –––––––––––––––––––––––––––––––––––––––––––––––
+ |
+
+
+ |
+
+
+
+
+
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js
index de93137df..ad0505f2e 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.js
+++ b/backend/src/middleware/notifications/notificationsMiddleware.js
@@ -1,6 +1,8 @@
+import { pubsub, NOTIFICATION_ADDED } from '../../server'
import extractMentionedUsers from './mentions/extractMentionedUsers'
import { validateNotifyUsers } from '../validation/validationMiddleware'
-import { pubsub, NOTIFICATION_ADDED } from '../../server'
+import { sendMail } from '../helpers/email/sendMail'
+import { notificationTemplate } from '../helpers/email/templateBuilder'
const queryNotificationsEmails = async (context, notificationUserIds) => {
if (!(notificationUserIds && notificationUserIds.length)) return []
@@ -29,12 +31,6 @@ const queryNotificationsEmails = async (context, notificationUserIds) => {
}
}
-const sendNotificationEmails = async (notification, email) => {
- // Wolle
- console.log('sendNotificationEmails !!! notification.to.slug: ', notification.to.slug)
- console.log('sendNotificationEmails !!! email: ', email)
-}
-
const publishNotifications = async (context, promises) => {
let notifications = await Promise.all(promises)
notifications = notifications.flat()
@@ -48,10 +44,16 @@ const publishNotifications = async (context, promises) => {
console.log('notificationsEmailAddresses: ', notificationsEmailAddresses)
notifications.forEach((notificationAdded, index) => {
pubsub.publish(NOTIFICATION_ADDED, { notificationAdded })
- // Wolle
- // console.log('notificationAdded: ', notificationAdded)
- sendNotificationEmails(notificationAdded, notificationsEmailAddresses[index].email)
+ // Wolle await
+ sendMail(
+ notificationTemplate({
+ email: notificationsEmailAddresses[index].email,
+ notification: notificationAdded,
+ }),
+ )
})
+ // Wolle
+ // return XXX successful?
}
const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => {