Having trouble with setting up my Nodemailer, looking for assistance

For some time now, I've been struggling to configure nodemailer on my static website. The main issue I'm facing is getting the 'require' function to work properly at this moment. I am aware that I must be missing something in my setup - hence, I need another perspective to help me out.

Here's a snippet of the HTML:

<form name="betaForm" action="/betaForm" method="post">

    <div class="form-group" >
       <label for="contactName" style="float:left;">Contact Name</label>
       <input type="text" name="contactName" value="" class="form-control" id="contactName">
    </div>

    <div class="form-group">
       <label for="practiceName" style="float:left;">Practice Name</label>
       <input type="text" name="practiceName" value="" class="form-control" id="practiceName">
    </div>

    <div class="form-group">
       <label for="phone1" style="float:left;">Phone</label>
       <input type="text" name="phone1" value="" class="form-control" id="phone1">
    </div>

    <div class="form-group">
       <label for="email1" style="float:left;">Email</label>
       <input type="email" name="email1" value="" class="form-control" id="email1">
    </div>

    <button type="submit" value="Send" class="btn btn-default">Submit</button>
</form>

Here's a section from SERVER.JS:

var express = require('express');
var nodemailer = require("nodemailer");
var app = express();

app.get('/',function(req,res){
  res.sendFile('www/index.html');
});

app.listen(3000,function(){
  console.log("Express Started on Port 3000");
});

And here's SENDMAIL.JS:

var app = require('express');
var nodemailer = require('nodemailer');
app.get('/betaForm', routes.betaForm);
app.post('/betaForm', function (req, res) {
  var mailOpts, smtpTrans;
  //Setting up Nodemailer transport using Gmail
  smtpTrans = nodemailer.createTransport('SMTP', {
     service: 'Gmail',
     auth: {
        user: "example@gmail.com",
        pass: "password"
     }
  });
  //Mail options
  mailOpts = {
     from: req.body.contactName + ' <' + req.body.email1 + '>', 
     to: 'recipient@example.com',
     subject: 'Beta Contact Form',
     text: req.body.contactName,
  };
  smtpTrans.sendMail(mailOpts, function (error, response) {
     if (error) {
        res.render('betaForm', { title: 'Beta Contact', msg: 'Error occurred, message not sent.', err: true, page: 'contact' })
     } else {
        res.render('betaForm', { title: 'Beta Contact', msg: 'Message sent! Thank you.', err: false, page: 'contact' })
     }
  });
});

Lastly, ROUTES.JS contains:

var exports = module.exports = {};
exports.betaForm = function(req, res){
    res.render('betaForm', { title: 'Beta Contact Form', page: '/#beta' })
};

Answer №1

Unfortunately, commenting is not within my capabilities.

Are you utilizing the bodyparser module?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding properties in a React component based on certain conditions using TypeScript

I am attempting to dynamically expand my component props based on whether a specific prop is included. The goal is to add attributes from an anchor if the href prop is provided, and include attributes from a button if it is not. Is this achievable? Chec ...

Creating a dynamic query in MongoDB: A step-by-step guide

Having trouble with setting up a dynamic query in mongoose, specifically for my video platform project. I'm working on building an advanced video search feature and I've included a snippet of the code: router.get("/search/video", async (req, re ...

React - triggering a router link action before the link is assigned a value

In this scenario, the issue arises because the URL changes before the link receives a value. The state is being received directly through the component but by the time it happens, the component has already been clicked. This results in the value being as ...

What is the reason for the index.html file not connecting to the local .css files and .js file?

I'm currently using node.js to send an .html file that includes the following tags: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="This is my personal profile website" /> <link r ...

Sending data from a Flask application written in Python to a JavaScript file using AJAX for seamless integration

As I am still in the learning process, please bear with me. I have been making attempts to find solutions, but often encounter issues when sending data of type="POST" from JavaScript to Flask using AJAX. This is the code snippet from my app.py f ...

Strategies for developing versatile controls that can adapt to the environment in which they are used?

Take a look at the image provided. In my application, I have three large black rectangles representing different forms in separate contexts. Across all three forms, there is a red box control present. The visibility and values of this red box are determin ...

Downloading files using headless Javascript with Selenium

Attempting to retrieve files from under headless conditions has proven challenging. Despite having a free account, the website seems to employ a series of javascript forms and redirections that complicate the process. In Firefox, I can extract the downloa ...

Is it necessary to distinguish between JS and PHP objects in an interaction diagram?

Currently, I am working on developing a communication diagram for an application that facilitates the purchase of books. Employing domain-driven design principles, my project involves three main objects: 'shop,' 'cart,' and 'book.& ...

Is there a way to append a URL parameter after a link is clicked using Vue.js?

I am currently working on integrating heading links on my website's sidebar that are linked to the main content using scrollspy. This allows users to easily navigate to different sections of the main content by clicking on the corresponding headings i ...

How can I determine the appropriate time to hide the loading screen after the model has been loaded with gltfLoader and before the scene is rendered?

I am currently working on a project using threejs version 106, where I have integrated both the webGLRenderer and CSS2DRenderer. My main challenge lies in loading a glb model and displaying a loading progress bar utilizing the onProgress callback of the l ...

Vue.js: API request taking too long during mounted lifecycle

I am facing an issue with API data in my Vue js project. The page loads quickly but the data from the API takes more than 5 seconds to load. Strangely, the API response appears very fast in the console. I have implemented the API in a separate file called ...

Avoiding an event from spreading in Angular

I am working on a navigation setup that looks like this: <a (click)="onCustomParameters()"> <app-custom-start-card></app-custom-start-card> </a> When the user clicks on the app-custom-start-card, the onCustomParame ...

Utilize the context API to efficiently share information from the parent to both its children and sibling children

I'm currently working on displaying fetched data in a child component using the context API, but encountering an error in the browser: TypeError: render is not a function The above error occurred in the component: in AppDataList (at App.j ...

Having trouble shutting down Metro Bundler on Windows?

While working on my React Native development, I regularly use npm start to get things going. However, I've run into an issue recently when trying to stop the process using Ctrl + c. It seems like I can no longer use npm start smoothly: ERROR Metro ...

Using JavaScript values retrieved from a database to dynamically adjust the options in the second dropdown menu based on the selection made in the

I am currently working on a feature that involves populating two dropdown menus with values from a database. The idea is that when an option is selected in the first dropdown, the second dropdown should dynamically display relevant values based on that s ...

What is the best way to retrieve a value from within several functions?

Below is the code I have been working on: (function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function() { this.addEventListener('load', function() console.log(this.responseTex ...

Reverse the columns in an Angular grid layout

We are currently utilizing angular-grid for showcasing a dynamic grid with multiple columns. For example: col1 col2 col3 col4 col5 col6 col7 col8 col9 colx Despite the columns being retrieved in the correct sequence, angular grid i ...

What is preventing me from applying JSON patches in both directions?

My current project involves merging JSON objects using patches following the guidelines outlined in RFC 7396. To achieve this, I am utilizing JSON Merge Patch along with Pretty JSON. Below is the code snippet I have: #!/usr/bin/env node var jsonmergepatch ...

After an asynchronous query using Mongoose in an Express route, I am unable to make any changes to the variable. It remains unchanged

I am facing an issue with modifying an empty array let last_activity = [] based on the result of a Mongoose query within an Express route. For troubleshooting purposes, I am currently trying to change it to [1, 2, 3]. Despite attempting different approache ...

What is the reason my answer for the powerset problem is flawed? Both my recursive and iterative methods are attached for review

How can I generate all possible subsets from an array of unique integers? For instance, if I have powerSet[1,2,3], the expected output should be [[], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]] I've tried a recursive approach: function powerset(arr ...