Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
form-to-mail
Advanced tools
Readme
Form To mail is a simple way to receive emails ✉ from contact forms on your website. Which handles files uploads on the fly for you Out of the box itself. Just Plugin the formToMail middleware and setup the .env variable's. You are good to go.
In development test SMTP service account from ethereal.email are generated and Preview URL's are logged. you can visit them to view the emails.
npm install form-to-mail
Loading and configuring the module can be done using CJS ( .cjs or .js ) & ESM ( .mjs ).
Form To Mail Supports both CJS and ESM.
By default, Node.js treats JavaScript code as CommonJS modules. Because of this, CommonJS modules are characterized by the require() statement for module imports and module.exports for module exports.
CommonJS (CJS)
const formToMail = require('form-to-mail')
.. or using ES6? ES Modules (ESM)
import formToMail from 'form-to-mail'
Create a .env
file in the root of your project with below environmental variables and fill them with your credentials.
# SMTP
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASSWORD=
#Mail Options
MAIL_FROM_NAME=
MAIL_FROM_EMAIL=
MAIL_TO_NAME=
MAIL_TO_EMAIL=
MAIL_CC_EMAIL=
MAIL_BCC_EMAIL=
All email addresses can be plain email addresses 'foobar@example.com'
or with formatted name (includes unicode support) 'Ноде Майлер <foobar@example.com>'
#Mail Options
MAIL_FROM_NAME= Sender Name
MAIL_FROM_EMAIL= Sender@example.com
MAIL_TO_EMAIL= to@example.com, "receiver" <receiver@example.com>
MAIL_CC_EMAIL= 'cc@example.com',"foo" <bar@example.com>,'Name' <baz@example.com>
MAIL_BCC_EMAIL= 'BCC@example.com',"Ноде Майлер" <foobar@example.com>,"Майлер, Ноде" <foobar@example.com>
Notice that all address fields are comma separated lists, so if you want to use a comma ( or any other special symbol ) in the name part, make sure you enclose the name in double quotes like this: ' "Майлер, Ноде" '
Suppose you have this HTML from in your contact page.Set the form action URL to your Custom endpoint.
contact-form.html
<form action="/" method="POST">
<div>
<label for="name" class="form-label"> Full Name </label>
<input type="text" name="name" id="name" placeholder="Full Name" class="form-input" />
</div>
<div>
<label for="email" class="form-label"> Email Address </label>
<input type="email" name="email" id="email" placeholder="Enter your email" class="form-input"/>
</div>
<div>
<label for="subject" class="form-label"> Subject </label>
<input type="text" name="subject" id="subject" placeholder="Enter your subject" class="form-input"/>
</div>
<div class="mb-5">
<label for="message" class="form-label"> Message </label>
<textarea rows="6" name="message" id="message" placeholder="Type your message" class="form-input"></textarea>
</div>
<div>
<button class="form-btn">Submit</button>
</div>
</form>
creates the routes for the POST endpoint. and add formToMail middleware which will handle the form submission for you. After that you can redirect the users to a confirmation / thank you page or you cloud send a custom response. You can access fields and files with the request Object.
app.post('/',formToMail, (req, res) => {
const fields = req.fields
const files = req.files
console.log('fields: ', fields)
console.log('files: ', files)
res.redirect(303, '/thank-you')
})
app.js
const express = require('express')
const app = express()
const port = 3000
const formToMail = require('form-to-mail')
app.get('/', (req, res) => res.sendFile('contact-form.html'))
app.get('/thank-you', (req, res) => res.sendFile('thank-you.html'))
// POST endpoint
app.post('/',formToMail, (req, res) => {
res.redirect(303, '/thank-you');
})
app.listen(port, () => console.log(`listening on port ${port}!`))
Sample Form Submission
You can find the sample Contact and Thank you pages inside the test folder.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)FAQs
A Simple Form Mailer. ✉
The npm package form-to-mail receives a total of 0 weekly downloads. As such, form-to-mail popularity was classified as not popular.
We found that form-to-mail demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.