Created
May 24, 2018 10:27
-
-
Save ValeryC/7af48ae0b09efbd3c67ac9dfd57d350c to your computer and use it in GitHub Desktop.
quete nodemailer . try on postman the methode get: http://localhost:4000/mail/askForCookiesRecipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express") | |
const mail = require("./routes/index.js") | |
const app = express() | |
app.use(express.json()) | |
app.use(express.urlencoded()) | |
app.use('/mail', mail); | |
app.listen(4000) | |
//launch on terminal: node app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const router = express.Router(); | |
const nodemailer = require("nodemailer"); | |
/* GET home page. */ | |
router.get('/askForCookiesRecipe', (req, res, next) =>{ | |
// Configuration du SMTP avec Mailtrap | |
const transport = nodemailer.createTransport({ | |
host: "smtp.mailtrap.io", | |
port: 2525, | |
auth: { | |
user: "d29e13c59ceb0e", | |
pass: "952d33ba69cf92" | |
} | |
}); | |
// Caracteristiques du message à envoyer | |
transport.sendMail({ | |
from: "f4456f26df-5118cc@inbox.mailtrap.io", // Expediteur --> ici adresse fournit par mailtrap | |
to: "supergrandma@yopmail.com", // Destinataires | |
subject: "Recette cookies", // Objet du mail | |
text: "Salut Mamie, j'adore tes cookies, peux tu me donner la recette. Merci !!", // plaintext body // le champ text et html st identique, ils permettent | |
// de créer une alternative si l'un des 2 ne s'affiche pas | |
html: "<b>Salut Mamie, j'adore tes cookies, peux tu me donner la recette. Merci !!</b>" // html body | |
}, (error, res) => { | |
if(error){ | |
console.log(error); | |
}else{ | |
console.log("Message sent: " + res.messageId); | |
} | |
}); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment