[英]Sending mail in Nuxt.js with nuxt-mail
我是 Nuxt.js/Vue.js 的新手,所以這里有一些新手問題:D
我在從 Nuxt.js 應用程序中的聯系人發送郵件時遇到問題。 我正在嘗試使用 nuxt-mailer,但無法使其正常工作。 我已經安裝了axios
和nuxt-mail 。
我得到 500(內部服務器錯誤)。
所以我在nuxt.config.js
中添加了這個:
'@nuxtjs/axios',
['nuxt-mail', {
message: {
to: 'my-email',
},
smtp: {
host: "localhost",
port: 587,
},
}],
我應該把郵件放在我想在“收件人”中接收郵件的地方嗎? 我應該只在host
中使用localhost
還是http://localhost
? 最后,我應該為“端口”加上什么雙關語? 那是 3000 作為我本地主機上的帖子嗎?
好的,接下來,我在組件中的表單如下所示:
<template>
<div class="container">
<form>
<label for="name">Ditt namn</label>
<input id="name" type="text" v-model="name"/>
<label for="email">Din epostadress</label>
<input id="email" type="email" v-model="email"/>
<label for="phone">Telefon</label>
<input id="phone" type="phone" v-model="phone"/>
<label for="message"> Meddelande: </label>
<textarea id="message" v-model="message"/>
<button type="submit" @click.prevent="send">Send email </button>
</form>
</div>
</template>
腳本如下所示:
<script>
export default {
data: () => ({
name: '',
email: '',
phone: '',
message: '',
}),
methods: {
send() {
this.$mail.send({
name: this.name,
from: this.email,
phone: this.phone,
subject: 'Message from contact-form',
text: this.message,
})
}
}
}
</script>
那么可能是什么問題? 想知道我是否在 nuxt.config.js 文件中做錯了什么? 但我一點也不知道。
希望有人可以幫助:)
查看自述文件和nodemailer的相關頁面,它看起來像這樣:
to
指的是接收方的實際 email 地址,類似於kuro@yourdomain.com
defaults to 587 if is secure is false or 465 if true
(來自nodemailer
文檔)如果您將使用 Nuxt 應用程序的節點部分,這里有一篇博客文章來設置一些電子郵件: https://blog.lichter.io/posts/emails-through-nuxtjs/
這是一篇關於如何特別使用nuxt-mail
博文: https://dword-design.de/blog/sending-emails-with-nuxt-js-the-easy-way/
借助 Mailgun、Sendgrid、Mailchimp 等,您仍然需要在 Mailtrap 上使用郵件發送服務來完成這項工作。
您還可以為此使用 Netlify 函數: https://css-tricks.com/netlify-functions-for-sending-emails/或任何其他無服務器函數
正如您所看到的,配置並非微不足道,有多種方法可以實現這一點,但它本質上歸結為使用外部服務,特別是如果您打算只使用全靜態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.