dword-design / nuxt-mail

Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Other
247 stars 18 forks source link

How to send message to another recipient #233

Closed bobrov-site closed 6 months ago

bobrov-site commented 6 months ago

I have nuxt config file

mail: {
    message: {
      to: process.env.NUXT_ADMIN_MAIL_USER,
    },
    smtp: {
      host: 'smtp.mail.ru',
      port: 465,
      secure: true,
      auth: {
        user: process.env.NUXT_ADMIN_MAIL_USER,
        pass: process.env.NUXT_ADMIN_MAIL_PASSWORD,
      },
    }
  }

But, i want to send message to another recipient, not admin in nuxt config file. How can i do it? I have below my example code for sending. Can you please provide best practicies?

const  { $mail } = useNuxtApp();
    const from = useRuntimeConfig().public.adminMailUser
    console.log($mail, 'mail')
    try {
        await $mail.send({
            from: from,
            subject: subject,
            text: text,
            message: {
                to: to
            }
        })
    }
    catch (e) {
        return {
            error: e.message
        }
    }
bobrov-site commented 6 months ago

@dword-design can you help me with this problem?