better smtp setup, allow local sendmail, add secure flag, auth not required

This commit is contained in:
lesion 2022-06-23 13:07:46 +02:00
parent b436ff4772
commit 1862e0cb60
No known key found for this signature in database
GPG key ID: 352918250B012177
4 changed files with 65 additions and 26 deletions

View file

@ -4,22 +4,34 @@
v-card-text
p(v-html="$t('admin.smtp_description')")
v-form(v-model='isValid')
v-text-field(v-model='admin_email'
@blur="save('admin_email', admin_email )"
:label="$t('admin.admin_email')"
:label="$t('admin.sender_email')"
:rules="$validators.email")
v-text-field(v-model='smtp.host'
:label="$t('admin.smtp_hostname')"
:rules="[$validators.required('admin.smtp_hostname')]")
v-text-field(v-model='smtp.auth.user'
:label="$t('common.user')"
:rules="[$validators.required('common.user')]")
v-switch(v-model='smtp.sendmail'
:label="$t('admin.smtp_use_sendmail')")
v-text-field(v-model='smtp.auth.pass'
:label="$t('common.password')"
:rules="[$validators.required('common.password')]"
type='password')
template(v-if='!smtp.sendmail')
v-text-field(v-model='smtp.host'
:label="$t('admin.smtp_hostname')"
:rules="[$validators.required('admin.smtp_hostname')]")
v-text-field(v-model='smtp.port'
:label="$t('admin.smtp_port')"
:rules="[$validators.required('admin.smtp_port')]")
v-switch(v-model='smtp.secure'
:label="$t('admin.smtp_secure')")
v-text-field(v-model='smtp.auth.user'
:label="$t('common.user')")
v-text-field(v-model='smtp.auth.pass'
:label="$t('common.password')"
type='password')
v-card-actions
v-spacer
@ -31,14 +43,16 @@
import { mapActions, mapState } from 'vuex'
export default {
data ({ $store }) {
const smtp = { host: '', auth: { user: '', pass: '' } }
if ($store.state.settings.smtp) {
smtp.host = $store.state.settings.smtp.host
if ($store.state.settings.smtp.auth) {
smtp.auth.user = $store.state.settings.smtp.auth.user
smtp.auth.pass = $store.state.settings.smtp.auth.pass
}
}
const smtp = { auth: {}, ...$store.state.settings.smtp }
// if ($store.state.settings.smtp) {
// smtp.host = $store.state.settings.smtp.host
// if ($store.state.settings.smtp.auth) {
// smtp.auth.user = $store.state.settings.smtp.auth.user
// smtp.auth.pass = $store.state.settings.smtp.auth.pass
// } else {
// smtp.auth = {}
// }
// }
return {
isValid: false,
loading: false,
@ -47,13 +61,28 @@ export default {
}
},
computed: mapState(['settings']),
watch: {
'smtp.secure' (value) {
this.smtp.port = value ? 465 : 25
}
},
methods: {
...mapActions(['setSetting']),
async testSMTP () {
this.loading = true
try {
await this.setSetting({ key: 'smtp', value: this.smtp })
await this.$axios.$post('/settings/smtp', { smtp: this.smtp })
const smtp = JSON.parse(JSON.stringify(this.smtp))
console.error(smtp)
if (!smtp.auth.user) {
console.error('ma non sono qui dentro !??!')
delete smtp.auth
}
if (!smtp.secure) {
smtp.secure = false
smtp.ignoreTLS = true
}
// await this.setSetting({ key: 'smtp', value: JSON.parse(JSON.stringify(this.smtp)) })
await this.$axios.$post('/settings/smtp', { smtp })
this.$root.$message(this.$t('admin.smtp_test_success', { admin_email: this.admin_email }), { color: 'success' })
} catch (e) {
console.error(e)
@ -67,9 +96,15 @@ export default {
}
},
done () {
if (this.smtp.auth.pass) {
this.setSetting({ key: 'smtp', value: JSON.parse(JSON.stringify(this.smtp)) })
const smtp = JSON.parse(JSON.stringify(this.smtp))
if (!smtp.auth.user) {
delete smtp.auth
}
if (!smtp.secure) {
smtp.secure = false
smtp.ignoreTLS = true
}
this.setSetting({ key: 'smtp', value: smtp })
this.$emit('close')
},

View file

@ -85,7 +85,8 @@ export default {
computed: {
...mapState(['settings']),
showSMTPAlert () {
return !this.setup && (!this.settings.admin_email || !this.settings.smtp || !this.settings.smtp.host || !this.settings.smtp.auth.user)
return !this.setup &&
(!this.settings.admin_email || !this.settings.smtp || (!this.settings.smtp.sendmail && !this.settings.smtp.host))
},
instance_locale: {
get () { return this.settings.instance_locale },

View file

@ -229,10 +229,13 @@
"new_announcement": "New announcement",
"show_smtp_setup": "Email settings",
"smtp_hostname": "SMTP Hostname",
"smtp_port": "SMTP Port",
"smtp_secure": "SMTP Secure (TLS or STARTTLS)",
"smtp_description": "<ul><li>Admin should receive an email when anon event is added (if enabled).</li><li>Admin should receive email of registration request (if enabled).</li><li>User should receive an email of registration request.</li><li>User should receive email of confirmed registration.</li><li>User should receive a confirmation email when subscribed directly by admin.</li><li>Users should receive email to restore password when they forgot it</li></ul>",
"smtp_test_success": "A test email is sent to {admin_email}, please check your inbox",
"smtp_test_button": "Send a test email",
"admin_email": "Admin e-mail",
"smtp_use_sendmail": "Use sendmail",
"sender_email": "Sender e-mail",
"widget": "Widget",
"wrong_domain_warning": "The baseurl configured in config.json <b>({baseurl})</b> differs from the one you're visiting <b>({url})</b>",
"new_collection": "New collection",

View file

@ -227,7 +227,7 @@
"new_announcement": "Nuovo annuncio",
"show_smtp_setup": "Impostazioni email",
"widget": "Widget",
"smtp_description": "<ul><li>L'amministratore riceve una email quando viene aggiunto un evento anonimo (se abilitati).</li><li>L'amministratore riceve le mail di richiesta di registrazione (se abilitata).</li><li>L persone ricevono una mail di conferma della registrazione richiesta.</li><li>Le persone ricevono le email della registrazione confermata.</li><li>Le persone ricevono una mail di avviso quando vengono registrate direttamente da admin.</li><li>Le persone ricevono la mail per modificare la password quando l'hanno dimenticata</li></ul>",
"smtp_description": "<ul><li>L'amministratore riceve una email quando viene aggiunto un evento anonimo (se abilitati).</li><li>L'amministratore riceve le mail di richiesta di registrazione (se abilitata).</li><li>Le persone ricevono una mail di conferma della registrazione richiesta.</li><li>Le persone ricevono le email della registrazione confermata.</li><li>Le persone ricevono una mail di avviso quando vengono registrate direttamente da admin.</li><li>Le persone ricevono la mail per modificare la password quando l'hanno dimenticata</li></ul>",
"smtp_hostname": "SMTP Hostname",
"smtp_test_success": "Una mail di test è stata inviata all'indirizzo {admin_email}, controlla la tua casella di posta",
"smtp_test_button": "Invia una mail di prova",