<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shivangi Singh</title>
    <description>The latest articles on DEV Community by Shivangi Singh (@shivangisingh1).</description>
    <link>https://dev.to/shivangisingh1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F753645%2F4335f1be-b153-47ff-b620-c6ed452bc601.jpg</url>
      <title>DEV Community: Shivangi Singh</title>
      <link>https://dev.to/shivangisingh1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivangisingh1"/>
    <language>en</language>
    <item>
      <title>Submit form and receive Email using Node and Express</title>
      <dc:creator>Shivangi Singh</dc:creator>
      <pubDate>Thu, 03 Feb 2022 09:53:50 +0000</pubDate>
      <link>https://dev.to/shivangisingh1/how-to-submit-data-from-html-forms-558f</link>
      <guid>https://dev.to/shivangisingh1/how-to-submit-data-from-html-forms-558f</guid>
      <description>&lt;p&gt;My last post was about a website that sends form requests from html form to my email account and in this post, I'll provide step by step, code along process of achieving this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;In this tutorial, I'll use Nodejs and Expressjs, so a basic understanding of them will work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let's get started!&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Setup
&lt;/h3&gt;

&lt;p&gt;In a completely new folder initialize the package.json file by opening the terminal or bash and write the command &lt;strong&gt;npm init -y&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now install the packages, for sending the emails I am using nodemailer and nodemailer-mailgun-transport will be the transporter. &lt;/p&gt;

&lt;p&gt;To install run the command: &lt;strong&gt;npm i express nodemailer nodemailer-mailgun-transport&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Now let's discuss how they work together in sending and receiving the mail with the express app.
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Nodemailer&lt;/strong&gt;  It is a Nodejs module for sending emails with SMTP or any other transporter mechanism. &lt;br&gt;
So the next step will be creating a Nodemailer transporter using either SMTP or some other transport mechanism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;nodemailer-mailgun-transport&lt;/strong&gt;  It is a transport layer to allow sending emails using Nodemailer and using the Mailgun API instead of the SMTP protocol. &lt;br&gt;
I'll describe how to use it in the code below.&lt;/p&gt;

&lt;p&gt;But if you are curious about how these packages work, visit the following links.&lt;br&gt;
&lt;a href="https://nodemailer.com/about/"&gt;npm nodemailer&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/nodemailer-mailgun-transport"&gt;npm nodemailer-transport&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Express Setup
&lt;/h3&gt;

&lt;p&gt;Make an app.js file and in this file first, we will require express and set a basic setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Q4JUe5x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggejy0n9zxg6ex55d4l4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Q4JUe5x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggejy0n9zxg6ex55d4l4.png" alt="express basic setup" width="545" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the res.sendFile we need to send our Html file, to send that file, firstly we will create a views folder and add index.html file in that.&lt;/p&gt;

&lt;p&gt;I have added a simple form you can add fields according to your requirements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--etwzzaxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23cxx2p78ytn7tm6qdqc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--etwzzaxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23cxx2p78ytn7tm6qdqc.png" alt="html setup" width="676" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will configure the Html file and add it to the sendFile.&lt;br&gt;
To do that I'll use the command.&lt;br&gt;
&lt;strong&gt;path.join(__dirname, 'views', 'index.html')&lt;/strong&gt;&lt;br&gt;
It will send the request to the path of Html file we added.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S4_s1d3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv4b18lgqtkn3pcvjof6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S4_s1d3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv4b18lgqtkn3pcvjof6.png" alt="implementing" width="880" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Making the Http request:
&lt;/h3&gt;

&lt;p&gt;We are done with the basic setup, so let's write a simple code to send an Http request. I will use fetch API to make the request.&lt;/p&gt;

&lt;p&gt;We will listen to the submit event on the form, disable the browser's default behavior and take the data entered by the user then send it to the path where the post request is waiting to receive that data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xnQsJie3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f5ibc1xj7q2e2qra4hv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xnQsJie3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f5ibc1xj7q2e2qra4hv.png" alt="http request" width="702" height="620"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After doing this we will try running the code and see if we receive the data in the terminal. &lt;br&gt;
Open your terminal and run the command &lt;strong&gt;node app.js&lt;/strong&gt; to run the file, you should be able to see the output in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R8Sne1Eh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqgshctkq507l7owmv9w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R8Sne1Eh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqgshctkq507l7owmv9w.png" alt="output" width="570" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mailgun
&lt;/h3&gt;

&lt;p&gt;We will use the mailgun API to receive the mails in our inbox. &lt;br&gt;
You need to first make your account and log in, after login you can get your domain name and your API key in your dashboard. And also validate yourself by adding your email account in which you want to receive the mails.&lt;br&gt;
&lt;a href="https://www.mailgun.com/"&gt;Mailgun&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Completing the mailing process
&lt;/h3&gt;

&lt;p&gt;Now we will make a mail.js file. &lt;br&gt;
In this file, we will write the code for sending the emails.&lt;/p&gt;

&lt;p&gt;First, include the 2 packages we installed in the beginning.&lt;br&gt;
Nodemailer and Nodemailer-mailgun-transport.&lt;br&gt;
Now to complete the process of sending the mail we need to add the auth which contains your API key and domain name from your mailgun account. After that, we will create the transport and then use the sendMail function to send the details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OIJPQyj7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l2ursrq2i6hs18cxdia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OIJPQyj7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l2ursrq2i6hs18cxdia.png" alt="mailjs" width="692" height="642"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are very close to completing the process. The data we are sending from the mail.js file should contain the information user entered in the form and to do that we just need to add this data in our sendMail function and to do that we will use the post request where we are receiving this data, then pass this info to the sendMail function. To achieve that we will make some changes to our sendMail function so we can add the fields dynamically.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DDLEcv_9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/33bzpkxcn9h6ge34qllk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DDLEcv_9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/33bzpkxcn9h6ge34qllk.png" alt="new changes in the function" width="473" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will import this function in our app.js file. In the post request, we will destructure the values from the req.body and then add them to our sendMail function with our callback function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GNphukFn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpg4n8eut8ktesm40ntx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GNphukFn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpg4n8eut8ktesm40ntx.png" alt="POST" width="586" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you should be able to send the mail and receive it in your inbox. Run your app.js file and see if you get the mail and yes check your spam folder too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Completed
&lt;/h3&gt;

&lt;p&gt;Now we are finally done with the work. You can use this in your projects to make your web apps interactive. If you get stuck in between don't worry I'll attach the GitHub link down.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/SHIVANGISINGH1/FormDemo.git"&gt;github Repo Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect with me on: &lt;br&gt;
&lt;a href="https://github.com/SHIVANGISINGH1"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/shivangi-singh-4686b5206/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>I made my first website which sends response from Html form to my Email.</title>
      <dc:creator>Shivangi Singh</dc:creator>
      <pubDate>Sun, 30 Jan 2022 12:57:46 +0000</pubDate>
      <link>https://dev.to/shivangisingh1/i-made-my-first-website-which-sends-response-from-html-form-to-my-email-1k4</link>
      <guid>https://dev.to/shivangisingh1/i-made-my-first-website-which-sends-response-from-html-form-to-my-email-1k4</guid>
      <description>&lt;p&gt;I made a simple static website which receives response from the user and send them to my email account. &lt;/p&gt;

&lt;h5&gt;The idea to create this website came from the need of providing free career guidance/counselling to the students of 10th &amp;amp; 12th class.&lt;/h5&gt;

&lt;p&gt;So I created a simple website using Html, Css and javascript.&lt;/p&gt;

&lt;p&gt;The other technologies used in the website were node and express for mailing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b1u-Y6uN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr12wxcsuqohjdw57jzk.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b1u-Y6uN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr12wxcsuqohjdw57jzk.jpeg" alt="Home Page Image Of my site" width="710" height="1223"&gt;&lt;/a&gt;&lt;br&gt;
I have used 2 npm package &lt;strong&gt;node mailer&lt;/strong&gt; and &lt;strong&gt;nodemailer-mailgun-transport&lt;/strong&gt;. With the help of these packages I was able to send and receive the mails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v2Z5P0qA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwo9s1622p3ebrgye74c.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v2Z5P0qA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwo9s1622p3ebrgye74c.jpeg" alt="Form Image" width="715" height="1302"&gt;&lt;/a&gt;&lt;br&gt;
After the completion of the website, I deployed it on &lt;strong&gt;Heroku&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://freecareerguidance.herokuapp.com/"&gt;Visit the Site&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; If you liked my idea please share it with students, so they can avail this opportunity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow me on&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/SHIVANGISINGH1"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/shivangi-singh-4686b5206/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
    </item>
  </channel>
</rss>
