Skip to content

Instantly share code, notes, and snippets.

@KarmaBlackshaw
Last active June 14, 2022 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarmaBlackshaw/afb44f2b4b04da61c96c31c356238559 to your computer and use it in GitHub Desktop.
Save KarmaBlackshaw/afb44f2b4b04da61c96c31c356238559 to your computer and use it in GitHub Desktop.
A basic implementation of Email services in javascript
import email from 'emailjs-com'
const serviceId = '' /* your service id */
const templateId = '' /* your template id */
const userId = '' /* your user id */
export default {
/**
* from_name
* from_email
* message
*/
send (templateParams) {
return email.send(serviceId, templateId, templateParams, userId)
}
}
const nodemailer = require('nodemailer')
const NODEMAILER_USER = '' /** your gmail */
const NODEMAILER_PASS = '' /** your password */
const NODEMAILER_SUBJECT = '' /** subject */
const sendMail = async ({ email, text, html } = {}) => {
try {
if (!NODEMAILER_USER || !NODEMAILER_PASS || !NODEMAILER_SUBJECT) {
return console.log('Invalid email credentials')
}
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: NODEMAILER_USER,
pass: NODEMAILER_PASS
}
})
const info = await transporter.sendMail({
from: NODEMAILER_USER,
to: email,
subject: NODEMAILER_SUBJECT,
text: text,
html
})
console.log('email sent successfully')
return info
} catch (error) {
throw error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment