.Vue-email is actually motivated by react-email, it permits our team make templates using the vue structure, along with elements that assist our company create design templates easily and also quickly.To start utilizing vue-email in any sort of vue task, you merely need to have to mount the package deal:.With NPM:.$ npm set up vue-email.Along with Anecdote:.$ yarn incorporate vue-email.Along with PNPM:.$ pnpm set up vue-email.Creating e-mail template.Develop a brand new e-mail design template in any place you wish to have your templates, for this instance, our experts can easily produce a theme directory, along with a design template called welcome.vue.src/templates/welcome. vue.
title, appreciated to vue-email.A Vue part public library for building reactive emails.Perspective on GitHub.Happy coding!David Arenas.
Rendering the design templates.Our team can use the provide function, it obtains two params, the initial one is actually the theme to render, and also the second the params to become utilized for the layout, and then pass the outcome layout in the body of demand.Passing the design template in the body system, give us the odds of rendering making use of any sort of hosting server, show, fastify, nuxt in SSR, etc src/pages/index. vue.Deliver email with nodemailer.Delivered email.
Send out e-mail.In this particular example i making use of nuxt v3 due to the fact that it allows our team to establish api inside very own project, as well as describe various api courses.Listed below our company only remove the theme of the demand body system, and send the e-mail passing the design template in the sendMail feature of the nodemailer package deal.src/server/api/ email.post.ts.bring in nodemailer coming from 'nodemailer'.export nonpayment defineEventHandler( async (celebration) => const body = await readBody( activity).const testAccount = wait for nodemailer.createTestAccount().const carrier = nodemailer.createTransport( ).const options = coming from: 'you@example.com',.to: 'user@gmail.com',.subject: 'hi there planet',.html: body.template,..wait for transporter.sendMail( options). ).If you are actually not utilizing the server in nuxt, you can simply execute on any type of framework for example making use of express:.bring reveal coming from 'express'.import nodemailer from 'nodemailer'.const app = show().app.use( express.json()).app.post('/ api/send-email', async (req, res) => const layout = req.body.const testAccount = wait for nodemailer.createTestAccount().const transporter = nodemailer.createTransport( 'smtp.ethereal.email',.port: 587,.safe and secure: inaccurate,.auth: consumer: testAccount.user,.successfully pass: testAccount.pass,.,. ).const choices = from: 'you@example.com',.to: 'user@gmail.com',.topic: 'hello there world',.html: layout,..wait for transporter.sendMail( options).profit res.json( information: "Email sent out" ). ).app.listen( 3001 ).Records.Obtain the full documentation [below] ().Elements.You can easily observe the elements, listed below:.Assimilations.E-mails developed along with vue-email may be converted into HTML or even.plain text, and also sent making use of any type of e-mail company. You can easily see.examples here:.