Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var router = express.Router();
- // Envoyer un email
- const nodemailer = require("nodemailer");
- app.use('/askForCookiesRecipe', router);
- router.post('/', askCookie); // handle the route at yourdomain.com/askForCookiesRecipe
- function askCookie(req, res){
- // Not the movie transporter!
- var transporter = nodemailer.createTransport({
- service: 'Gmail',
- auth: {
- user: 'monmail@gmail.com', // Your email id
- pass: 'password' // Your password
- }
- });
- var mailOptions = {
- from: 'mauriceandmarcel@gmail.com', // sender address
- to: 'supergrandma@yopmail.com', // list of receivers
- subject: 'Ta recette de cookie Mamie !', // Subject line
- // text: text //, // plaintext body
- html: "<b>Salut Mamie, tu me file t'a recette de cookie ?</b>" // You can choose to send an HTML body instead
- };
- transporter.sendMail(mailOptions, function(error, info){
- if(error){
- console.log(error);
- res.json({yo: 'error'});
- }else{
- console.log('Message sent: ' + info.response);
- res.json({yo: info.response});
- };
- });
- }
- // mount the router on the app
- //app.use('/', router);
- module.exports = router;
Add Comment
Please, Sign In to add comment