所以我尝试在用户填写表单后使用 nuxt-mail 发送电子邮件。一封电子邮件应该是我的,另一封应该发送到他在电子邮件字段中输入的电子邮件,以便他可以得到电子邮件已发送的确认。但问题是我必须在 nuxt.config.js 中定义它发送到的电子邮件,这意味着它在表单中输入的内容不可变。 我怎样才能给它一个额外的变量电子邮件来发送到?
我有我的nuxt.config.js:(smtp数据是由Ethereal生成的,所以它是虚拟数据并且不敏感)
export default defineNuxtConfig({
devtools: { enabled: true },
modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt', ['nuxt-mail', {
message: {
to: '[email protected]',
},
smtp: {
host: "smtp.ethereal.email",
port: 587,
auth: {
user: '[email protected]',
pass: 'eAWgGNgmeBH95ce9Sm'
}
},
}]],
})
我这样称呼它:
<script>
export default {
methods: {
sendEmail() {
this.$mail.send({
from: 'John Doe',
subject: 'Incredible',
text: 'This is an incredible test message',
})
},
},
}
</script>
这工作正常并发送到 [电子邮件受保护],但我需要以某种方式添加它应该发送到的另一个电子邮件地址 我试过这样:
<script>
export default {
methods: {
sendEmail() {
this.$mail.send({
message:{
to:'[email protected]'
},
from: 'John Doe',
subject: 'Incredible',
text: 'This is an incredible test message',
})
},
},
}
</script>
我也尝试过这个:
<script>
export default {
methods: {
sendEmail() {
this.$mail.send({
to:'[email protected]',
from: 'John Doe',
subject: 'Incredible',
text: 'This is an incredible test message',
})
},
},
}
</script>
但这没有用。那么还有其他方法可以做到这一点吗?
如果你想发送邮件,那么我建议你使用Nodemailer;它很容易使用,Nodemailer 是一个广泛使用的多功能库,用于发送电子邮件。