Created
February 3, 2023 14:12
-
-
Save Chojiu15/9af5dae2b4ba11fff36da1a398744626 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 app = express() | |
| const mongoose = require('mongoose') | |
| app.use(express.urlencoded({ | |
| extended : true | |
| })) | |
| const User = require('./models/user') | |
| const nodemailer = require('nodemailer') | |
| const transporter = nodemailer.createTransport({ | |
| service: 'gmail', | |
| auth: { | |
| user: 'd', | |
| pass: '' | |
| } | |
| }); | |
| app.get('/send-email', async (req, res) => { | |
| try { | |
| // Find a user in the database | |
| const user = await User.findOne({ email: req.params.email }); | |
| // Send the email | |
| await transporter.sendMail({ | |
| from: '', | |
| to: '', | |
| subject: 'Test email', | |
| text: 'Hello, this is a test email from my server' | |
| }); | |
| res.send('Email sent successfully'); | |
| } catch (error) { | |
| console.error(error); | |
| res.send('An error occurred'); | |
| } | |
| }); | |
| mongoose.connect('mongodb+srv://chojiu:[email protected]/myDB?retryWrites=true&w=majority', {useNewUrlParser : true}) | |
| app.listen(3000, () => { | |
| console.log('Server running') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment