Skip to content

Commit 2ef1ade

Browse files
committed
email flask exp
1 parent f90efb8 commit 2ef1ade

7 files changed

Lines changed: 491 additions & 0 deletions

File tree

express-email/done/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const express = require('express')
2+
const bodyParser = require('body-parser')
3+
4+
const nodemailer = require("nodemailer");
5+
6+
const app = express()
7+
const port = 3000
8+
9+
// parse application/x-www-form-urlencoded
10+
app.use(bodyParser.urlencoded({ extended: false }))
11+
12+
// parse application/json
13+
app.use(bodyParser.json())
14+
15+
16+
app.get('/', (req, res) => {
17+
res.send('Hello vro!')
18+
})
19+
20+
app.post('/', async (req, res) => {
21+
const {email} = req.body;
22+
// create reusable transporter object using the default SMTP transport
23+
let transporter = nodemailer.createTransport({
24+
host: "smtp.ethereal.email",
25+
port: 587,
26+
secure: false, // true for 465, false for other ports
27+
auth: {
28+
user: 'da...@ethereal.email', // ethereal user
29+
pass: 'aJ...', // ethereal password
30+
},
31+
});
32+
33+
const msg = {
34+
from: '"The Exapress App" <theExpressApp@example.com>', // sender address
35+
to: `${email}`, // list of receivers
36+
subject: "Sup", // Subject line
37+
text: "Long time no see", // plain text body
38+
}
39+
// send mail with defined transport object
40+
const info = await transporter.sendMail(msg);
41+
42+
console.log("Message sent: %s", info.messageId);
43+
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
44+
45+
// Preview only available when sending through an Ethereal account
46+
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
47+
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
48+
49+
res.send('Email Sent!')
50+
})
51+
52+
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

0 commit comments

Comments
 (0)