You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use nuxt-mail server-side with Nuxt but I can't figure out how to import it . Working as expected in client but I would prefer avoid it. Is the project allowing it?
Here is my basic test api:
// server/api/test-mail.js// import { useMail } from "#imports"// import useEmail from 'nuxt-mail'import{useEmail}from'nuxt-mail'exportdefaultdefineEventHandler(async(event)=>{constmail=useMail()// const body: any = await readBody(event)// sanitize sanitize sanitize sanitize sanitize sanitize sanitizeconsole.log('Test email')try{mail.send({config: 'contact',from: 'John Doe',subject: 'Test nuxt-mail',text: 'This is an incredible test message',})}catch(e){console.error(e)// [nuxt] [request error] [unhandled] [500] useMail is not definedthrowcreateError({statusCode: 500,})}})
// Client side
<script lang="ts" setup>
const { error, execute, status } =awaituseFetch(():string=>'/api/test-mail', { immediate: false,})// Works/*const mail = useMail()function send() { try { mail.send({ from: 'John Doe', subject: 'Test nuxt-mail', text: 'This is an incredible test message', }) } catch (e) { console.error(e) }}*/
</script>
<template>
<div>
<button@click="execute">
Send email
</button>
<div>{{ status }}</div>
<divv-if="error">
{{ error }}
</div>
</div>
</template>
Thanks.
The text was updated successfully, but these errors were encountered:
Hello.
I'm trying to use nuxt-mail server-side with Nuxt but I can't figure out how to import it . Working as expected in client but I would prefer avoid it. Is the project allowing it?
Here is my basic test api:
Thanks.
The text was updated successfully, but these errors were encountered: