|
1 |
| -const express = require("express"); |
2 |
| -const app = express(); |
3 |
| -const cors = require("cors"); |
4 |
| -const nodemailer = require("nodemailer"); |
5 |
| -const bodyparser = require("body-parser"); |
6 |
| -const dotenv = require("dotenv").config(); |
7 |
| - |
8 |
| -const { PORT, CLIENT_URLS, EMAIL_PASS, EMAIL_USER, EMAIL_REPORT } = process.env; |
9 |
| - |
10 |
| -const whitelist = CLIENT_URLS.split(","); |
11 |
| - |
12 |
| -app.use(express.json()); |
13 |
| -app.use(bodyparser.json()); |
14 |
| -app.use( |
15 |
| - cors({ |
16 |
| - origin: function (origin, callback) { |
17 |
| - if (whitelist.indexOf(origin) !== -1) { |
18 |
| - callback(null, true); |
19 |
| - } else { |
20 |
| - callback(new Error("Not allowed by CORS")); |
21 |
| - } |
22 |
| - }, |
23 |
| - }) |
24 |
| -); |
25 |
| - |
26 |
| -const emailStyles = |
27 |
| - "<style>.ltr{text-align:left;}.rtl{text-align:right;}.editor-text-bold{font-weight:bold;}.editor-text-italic{font-style:italic;}.editor-text-underline{text-decoration:underline;}.editor-text-strikethrough{text-decoration:line-through;}.editor-text-underlineStrikethrough{text-decoration:underlineline-through;}.editor-text-code{background-color:#ccc;padding:1px0.25rem;font-family:Menlo,Consolas,Monaco,monospace;font-size:94%;}.editor-link{color:rgb(33,111,219);text-decoration:none;}.editor-code{background-color:#ccc;font-family:Menlo,Consolas,Monaco,monospace;display:block;padding:8px 8px 8px 52px;line-height:1.53;font-size:13px;margin:0;margin-top:8px;margin-bottom:8px;tab-size:2;overflow-x:auto;position:relative;}.editor-code:before{content:attr(data-gutter);position:absolute;background-color:#ddd;left:0;top:0;border-right:1px solid #ccc;padding:8px;color:#777;white-space:pre-wrap;text-align:right;min-width:25px;}.editor-code:after{content:attr(data-highlight-language);top:0;right:3px;padding:3px;font-size:10px;text-transform:uppercase;position:absolute;color: #000;}.editor-tokenComment{color:slategray;}.editor-tokenPunctuation{color:#999;}.editor-tokenProperty{color:#905;}.editor-tokenSelector{color:#690;}.editor-tokenOperator{color:#9a6e3a;}.editor-tokenAttr{color:#07a;}.editor-tokenVariable{color:#e90;}.editor-tokenFunction{color:#dd4a68;}.editor-paragraph{margin:0;margin-bottom:8px;position:relative;}.editor-paragraph:last-child{margin-bottom:0;}.editor-heading-h1{font-size:24px;margin:0;margin-bottom:12px;padding:0;}.editor-heading-h2{font-size:16px;margin:0;margin-top:10px;padding:0;}.editor-quote{margin:0;margin-left:20px;font-size:15px;color:rgb(101,103,107);border-left-color:rgb(206,208,212);border-left-width:4px;border-left-style:solid;padding-left:16px;}.editor-list-ol{padding:0;margin:0;margin-left:16px;list-style-type:decimal;}.editor-list-ul{list-style-type:circle;padding:0;margin:0;margin-left:16px;}.editor-listitem{margin:8px 32px 8px 32px;}.editor-nested-listitem{list-style-type:none;}</style>"; |
28 |
| - |
29 |
| -let transporter = nodemailer.createTransport({ |
30 |
| - host: "smtp-mail.outlook.com", |
31 |
| - service: "outlook", |
32 |
| - secureConnection: false, |
33 |
| - tls: { |
34 |
| - ciphers: "SSLv3", |
35 |
| - }, |
36 |
| - port: 587, |
37 |
| - auth: { |
38 |
| - user: EMAIL_USER, |
39 |
| - pass: EMAIL_PASS, |
40 |
| - }, |
41 |
| -}); |
42 |
| - |
43 |
| -const sendEmail = async (subject, message, to, from, attachments = []) => { |
44 |
| - const options = { |
45 |
| - from: from, |
46 |
| - to: to, |
47 |
| - subject: subject, |
48 |
| - html: message, |
49 |
| - attachments: attachments, |
50 |
| - }; |
51 |
| - |
52 |
| - transporter.sendMail(options, (err, info) => { |
53 |
| - if (err) { |
54 |
| - console.log(err); |
55 |
| - } |
56 |
| - }); |
57 |
| -}; |
58 |
| - |
59 |
| -app.post("/send_email", async (req, res) => { |
60 |
| - const { subject, message, attachments } = req.body; |
61 |
| - |
62 |
| - try { |
63 |
| - await sendEmail( |
64 |
| - subject, |
65 |
| - `<html><head>${emailStyles}</head><body>${message}</body></html>`, |
66 |
| - EMAIL_REPORT, |
67 |
| - EMAIL_USER, |
68 |
| - attachments |
69 |
| - ); |
70 |
| - res.status(200).json({ message: "Report submitted!" }); |
71 |
| - } catch (e) { |
72 |
| - res.status(500).json({ error: e }); |
73 |
| - } |
74 |
| -}); |
75 |
| - |
76 |
| -app.listen(PORT, () => { |
77 |
| - console.log("Server started"); |
78 |
| -}); |
| 1 | +export const emailStyles = |
| 2 | + '<style>.ltr{text-align:left;}.rtl{text-align:right;}.editor-text-bold{font-weight:bold;}.editor-text-italic{font-style:italic;}.editor-text-underline{text-decoration:underline;}.editor-text-strikethrough{text-decoration:line-through;}.editor-text-underlineStrikethrough{text-decoration:underlineline-through;}.editor-text-code{background-color:#ccc;padding:1px0.25rem;font-family:Menlo,Consolas,Monaco,monospace;font-size:94%;}.editor-link{color:rgb(33,111,219);text-decoration:none;}.editor-code{background-color:#ccc;font-family:Menlo,Consolas,Monaco,monospace;display:block;padding:8px 8px 8px 52px;line-height:1.53;font-size:13px;margin:0;margin-top:8px;margin-bottom:8px;tab-size:2;overflow-x:auto;position:relative;}.editor-code:before{content:attr(data-gutter);position:absolute;background-color:#ddd;left:0;top:0;border-right:1px solid #ccc;padding:8px;color:#777;white-space:pre-wrap;text-align:right;min-width:25px;}.editor-code:after{content:attr(data-highlight-language);top:0;right:3px;padding:3px;font-size:10px;text-transform:uppercase;position:absolute;color: #000;}.editor-tokenComment{color:slategray;}.editor-tokenPunctuation{color:#999;}.editor-tokenProperty{color:#905;}.editor-tokenSelector{color:#690;}.editor-tokenOperator{color:#9a6e3a;}.editor-tokenAttr{color:#07a;}.editor-tokenVariable{color:#e90;}.editor-tokenFunction{color:#dd4a68;}.editor-paragraph{margin:0;margin-bottom:8px;position:relative;}.editor-paragraph:last-child{margin-bottom:0;}.editor-heading-h1{font-size:24px;margin:0;margin-bottom:12px;padding:0;}.editor-heading-h2{font-size:16px;margin:0;margin-top:10px;padding:0;}.editor-quote{margin:0;margin-left:20px;font-size:15px;color:rgb(101,103,107);border-left-color:rgb(206,208,212);border-left-width:4px;border-left-style:solid;padding-left:16px;}.editor-list-ol{padding:0;margin:0;margin-left:16px;list-style-type:decimal;}.editor-list-ul{list-style-type:circle;padding:0;margin:0;margin-left:16px;}.editor-listitem{margin:8px 32px 8px 32px;}.editor-nested-listitem{list-style-type:none;}</style>'; |
0 commit comments