diff --git a/.env.example b/.env.example
index 77b7e44..922efee 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,9 @@
SESSION_SECRET=
MONGODB_CONN="mongodb://127.0.0.1:27017/howfeed"
SALT_WORK_FACTOR=10
+
+SMTP_SERVER=
+SMTP_PORT=587
+SMTP_USERNAME=
+SMTP_PASSWORD=
+SMTP_RECIPIENTS="a@example.com, b@example.com"
diff --git a/package-lock.json b/package-lock.json
index 25ea069..d4ed28e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4896,6 +4896,11 @@
"integrity": "sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==",
"dev": true
},
+ "nodemailer": {
+ "version": "6.4.11",
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.11.tgz",
+ "integrity": "sha512-BVZBDi+aJV4O38rxsUh164Dk1NCqgh6Cm0rQSb9SK/DHGll/DrCMnycVDD7msJgZCnmVa8ASo8EZzR7jsgTukQ=="
+ },
"nopt": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
diff --git a/package.json b/package.json
index 9e3aa93..1e9dd35 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"helmet": "^3.23.3",
"mongoose": "^5.10.2",
"mongoose-fuzzy-searching": "^1.3.1",
+ "nodemailer": "^6.4.11",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"rate-limiter-flexible": "^2.1.10",
diff --git a/src/routes/contact.svelte b/src/routes/contact.svelte
index 66ebf72..e23b4dd 100644
--- a/src/routes/contact.svelte
+++ b/src/routes/contact.svelte
@@ -2,6 +2,33 @@
Contact Us | HOWFEED.BIZ
+
+
+ Suggest Ideas to Us
+ Do you have a request for an article or an enhancement to the site? Send it directly to us here!
+
+ Come Find Us!
diff --git a/src/server.js b/src/server.js
index 997862e..a045daf 100644
--- a/src/server.js
+++ b/src/server.js
@@ -9,6 +9,7 @@ import { Strategy } from 'passport-local';
import sessionFileStore from 'session-file-store';
import { RateLimiterMemory } from 'rate-limiter-flexible';
import fileUpload from 'express-fileupload';
+import nodemailer from 'nodemailer';
import fs from 'fs';
import cors from 'cors';
import helmet from 'helmet';
@@ -25,7 +26,8 @@ import legacyRouter from './legacy/router.js';
require('dotenv').config();
const FileStore = sessionFileStore(session);
-const { PORT, NODE_ENV, SESSION_SECRET, MONGODB_CONN } = process.env;
+const { PORT, NODE_ENV, SESSION_SECRET, MONGODB_CONN,
+ SMTP_USERNAME, SMTP_PASSWORD, SMTP_SERVER, SMTP_PORT, SMTP_RECIPIENTS } = process.env;
const dev = NODE_ENV === 'development';
mongoose.set('useNewUrlParser', true);
@@ -111,6 +113,16 @@ const isAuthor = function(req, res, next) {
}
};
+const mailer = nodemailer.createTransport({
+ host: SMTP_SERVER,
+ port: 587,
+ secure: SMTP_PORT === 465,
+ auth: {
+ user: SMTP_USERNAME,
+ pass: SMTP_PASSWORD
+ },
+});
+
var app = express();
app.set('view engine', 'ejs');
@@ -429,7 +441,44 @@ mainRouter
'Content-Type': 'application/rss+xml'
});
res.end(feed.xml());
- });
+ })
+ .post('/suggestions', async function (req, res) {
+ let { name, title, message } = req.body;
+ if (!message) {
+ res.writeHead(422, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: 'No message supplied'
+ }));
+ return false;
+ }
+ name = name || 'Anonymous';
+ title = title || 'Suggestion';
+ try {
+ await mailer.sendMail({
+ from: `"HowFeed Suggestions" <${SMTP_USERNAME}>`,
+ to: SMTP_RECIPIENTS,
+ subject: title,
+ text: `Suggested by ${name}:
+
+ ${message}`
+ });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: 'Your suggestion was delivered.'
+ }));
+ } catch (err) {
+ res.writeHead(500, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: err.message
+ }));
+ }
+ });
app.use(helmet())
.use(cors())