Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const nodemailer = require("nodemailer");
- const sendEmail = ({ recepient, subject, body, attachments }) => {
- const { EMAIL_ADDRESS,EMAIL_PASSWORD } = process.env;
- let transportOptions = {
- host: 'smtp.example.com',
- port: 587,
- secure: false,
- requireTLS: true,
- tls: {
- rejectUnauthorized: false
- },
- auth: {
- user: EMAIL_ADDRESS,
- pass: EMAIL_PASSWORD
- }
- }
- let transporter = nodemailer.createTransport(transportOptions);
- const mailOptions = {
- from: EMAIL_ADDRESS,
- to: recepient,
- subject,
- html: body,
- attachments: attachments || null
- };
- return transporter.sendMail(mailOptions);
- };
- module.exports = sendEmail;
- // #######
- // CLASS IMPLEMENTATION
- class EmailService {
- constructor(emailOpts = { recepient: '', attachments: [] }) {
- this.emailOpts = emailOpts
- }
- sendRegisterConfirmationLink(opts = { confirmationLink: '', recepient: '', body: '' }) {
- return sendEmail({
- ...this.emailOpts,
- recepient: opts.recepient,
- subject: 'Confirm your account',
- body: opts.body || `<p>Click on the link below to confirm your account: </p> <a href="${opts.confirmationLink}">Confirm account</a>`
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement