Need help with creating mail templates with dynamic data and sending it
Summary:
My goal is to send order confirmation emails using Nodemailer and Vue for email templates. I have successfully managed to:
1. Send emails using Nodemailer with SMTP.
2. Create email templates using Vue-mail but I did not use nuxt components? im not sure I am new to this nuxt module. Though I was able to use Tailwind in the email template.
However, I am encountering issues when trying to combine these functionalities.
9 Replies
What I have tried:
1. Sending Emails with Nodemailer:
I have a working implementation that sends emails using Nodemailer. Here is the relevant code:
2. Creating Email Templates with Vue:
I have created a template using Vue components and props. Here is the template:
3. Combining Both:
I tried to combine both functionalities by creating an API endpoint that generates the email HTML and sends the email. Here is the code:
Issues Encountered:
1. When trying to display the email HTML in the page's body, I get warnings like "missing required prop".
2. In the server console, I get the following error:
I am using Pinia for state management and want to pass the data from the Pinia states to the email template and send it with Nodemailer. The checkout store has a
formData
state that contains all the relevant data about the customer like name, email, phone, address, etc.
I would appreciate any guidance or suggestions on how to resolve these issues and successfully combine sending emails with Nodemailer and creating email templates with Vue-Mail.
I did use Claude and Github Copilot for help.I'm just running into this. Did you ever manage to fix this issue? I tried adding this to
nuxt.config.ts
but I still get the rollup error...
@YassaaaI dont think that you could use nuxt components in mail tempaltes because those use pure html+css.
what I ended up doing in another project was in a utils folder I created:
-
emailSections.ts
- emailStyles.ts
- emailTemplate.ts
here is the code in order:
then I created a contact.post.ts
in server/api/
code:
I hope this answers your question 🙂
If it was not clear I used nuxt-nodemailer
module.
so ofc you need to make sure you configured it so it can work. 👍
in nuxt.config.ts
:
Actually, I managed to make it work!
This does the trick. I had two
nitro
objects in my config, so this plugin was getting overwritten.
@Yassaaa I am aware not everything Vue does is available on an email, but you definitely can use it as a templating engine.Nuxt
nuxt-mail · Nuxt Modules
Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
vue-email seems interesting as I am using Resend to send emails and it is "inspired by the Resend team's React Email library".
Thanks, @Mak.