Skip to content

Commit

Permalink
Add nodemailer integration for form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
a26blass committed Apr 30, 2024
1 parent 65f7472 commit 66a4542
Show file tree
Hide file tree
Showing 50 changed files with 14,733 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Gmail App Password Kubernetes Secret
run: |
kubectl create secret generic gmail-secret --from-literal=GMAIL_PASSWORD="${{ secrets.GOOGLE_APP_PASSWORD }}"
- name: Update deployment
if: needs.check-changed-files.outputs.site-changed == 'true'
run: |
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /usr/src/app
COPY package*.json ./

ENV NODE_ENV=production
ENV GMAIL_PASSWORD=$GMAIL_PASSWORD

RUN npm install

Expand Down
34 changes: 31 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Default services are defined below
var createError = require('http-errors');
var express = require('express');
var path = require('path');
Expand All @@ -7,6 +8,20 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

// Custom services are defined below
const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
service: "Gmail",
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: "[email protected]",
pass: "process.env.GMAIL_PASSWORD",
},
});

var app = express();

// view engine setup
Expand Down Expand Up @@ -35,9 +50,22 @@ app.post('/submit', function(req, res) {
var message = req.body.message; // Get message from form data

console.log('New Message:: ' + name + ' :: ' + email + ' :: ' + message)

// Handle the form data (TODO)


const mailOptions = {
from: "[email protected]",
to: "[email protected]",
subject: "New Message From " + email,
text: "Name: " + name + "\n" + message
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error("Error sending email: ", error);
} else {
console.log("Email sent: ", info.response);
}
});

// Render the page with the confirmation message
res.render('index', { title: 'Form Submitted', confirmation: 'Form submitted successfully!', submitted: true });
});
Expand Down
Binary file removed helm/charts/cert-manager-v1.14.5.tgz
Binary file not shown.
8 changes: 8 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions node_modules/nodemailer/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/nodemailer/.ncurc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions node_modules/nodemailer/.prettierrc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 66a4542

Please sign in to comment.