diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-11-09 22:58:16 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-11-09 22:59:49 +0100 |
commit | 696c2c03269135a6e3cf9d802da30e2152d2664c (patch) | |
tree | 0da79e80c7a84f23d7ee0b508911be017163e5b4 | |
parent | 70289448796f6649d74a2ec22b300c3b0075b762 (diff) | |
download | server-696c2c03269135a6e3cf9d802da30e2152d2664c.tar.gz |
Send new message notifications by mail.
-rw-r--r-- | server.js | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -1099,6 +1099,18 @@ function mail_password_reset_token(user, token) { mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); } +function mail_new_message(user, msg_id, msg_from, msg_subject, msg_body) { + if (!mailer) + return; + let subject = "You have a new message from " + msg_from + "."; + let body = "Subject: " + msg_subject + "\n\n" + + msg_body + "\n\n" + + "https://rally-the-troops.com/message/read/" + msg_id + "\n\n" + + MAIL_FOOTER; + console.log("SENT MAIL:", mail_addr(user), subject); + mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); +} + function mail_your_turn_notification(user, game_id, interval) { let too_soon = sql_notify_too_soon.get(interval, user.user_id, game_id); if (!too_soon) { @@ -1780,9 +1792,9 @@ app.post('/message/send', must_be_logged_in, function (req, res) { message: "Cannot find that user." }); } - MESSAGE_SEND.run(req.user.user_id, to_user.user_id, subject, body); + let info = MESSAGE_SEND.run(req.user.user_id, to_user.user_id, subject, body); if (to_user.notifications) { - console.log("MAIL USER NOTIFICATION"); + mail_new_message(to_user, info.lastInsertRowid, req.user.name, subject, body) } res.redirect('/inbox'); }); |