Last active
June 14, 2022 08:18
-
-
Save KarmaBlackshaw/afb44f2b4b04da61c96c31c356238559 to your computer and use it in GitHub Desktop.
A basic implementation of Email services in javascript
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
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) | |
} | |
} |
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 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