Skip to content

Instantly share code, notes, and snippets.

@Chojiu15
Created February 3, 2023 14:12
Show Gist options
  • Save Chojiu15/9af5dae2b4ba11fff36da1a398744626 to your computer and use it in GitHub Desktop.
Save Chojiu15/9af5dae2b4ba11fff36da1a398744626 to your computer and use it in GitHub Desktop.
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