diff --git a/dashboard/src/models/MailModel.js b/dashboard/src/models/MailModel.js index 301f21838..91217de27 100644 --- a/dashboard/src/models/MailModel.js +++ b/dashboard/src/models/MailModel.js @@ -226,6 +226,17 @@ function create() { if (result.status !== 200) return [result]; return [null]; }, + async sendTestMail(domain, mailToAddress) { + let result; + try { + result = await fetcher.post(`${API_ORIGIN}/api/v1/mail/${domain}/send_test_mail`, { to: mailToAddress }, { access_token: accessToken }); + } catch (e) { + return [e]; + } + + if (result.status !== 202) return [result]; + return [null]; + } }; } diff --git a/dashboard/src/views/EmailsView.vue b/dashboard/src/views/EmailsView.vue index cd24dbeca..ae37b5e91 100644 --- a/dashboard/src/views/EmailsView.vue +++ b/dashboard/src/views/EmailsView.vue @@ -5,7 +5,7 @@ const i18n = useI18n(); const t = i18n.t; import { ref, onMounted, useTemplateRef } from 'vue'; -import { Button, TableView, FormGroup, TextInput, InputGroup, Switch, ButtonGroup, SingleSelect } from 'pankow'; +import { Button, TableView, InputDialog, FormGroup, TextInput, InputGroup, Switch, ButtonGroup, SingleSelect } from 'pankow'; import { prettyDecimalSize } from 'pankow/utils'; import Section from '../components/Section.vue'; import SettingsItem from '../components/SettingsItem.vue'; @@ -17,6 +17,7 @@ const domainsModel = DomainsModel.create(); const mailModel = MailModel.create(); const profileModel = ProfileModel.create(); +const inputDialog = useTemplateRef('inputDialog'); const columns = { status: { sort: true }, domain: { label: t('emails.domains.domain'), sort: true }, @@ -109,6 +110,27 @@ async function refreshStatus() { } } +async function onSendTestMail(domain) { + const address = await inputDialog.value.prompt({ + value: profile.value.email, + title: t('emails.testMailDialog.title', { domain: domain.domain }), + message: t('emails.testMailDialog.description', { domain: domain.domain }), + confirmLabel: t('emails.testMailDialog.sendAction'), + rejectLabel: t('main.dialog.cancel'), + rejectStyle: 'secondary' + }); + + if (!address) return; + + const [error] = await mailModel.sendTestMail(domain.domain, address); + if (error) { + window.pankow.notify({ text: error.body ? error.body.message : 'Failed to send mail', type: 'danger' }); + return console.error(error); + } + + window.pankow.notify({ text: 'Mail sent', type: 'success' }); +} + onMounted(async () => { let [error, result] = await profileModel.get(); if (error) return console.error(error); @@ -161,6 +183,8 @@ onMounted(async () => {