You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
9.0 KiB

  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-new-post.svg', alt='Mail', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:mail.title') }}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:mail.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
  12. v-icon(left) mdi-check
  13. span {{$t('common:actions.apply')}}
  14. v-form.pt-3
  15. v-layout(row wrap)
  16. v-flex(lg6 xs12)
  17. v-form
  18. v-card.animated.fadeInUp
  19. v-toolbar(color='primary', dark, dense, flat)
  20. v-toolbar-title.subtitle-1 {{ $t('admin:mail.configuration') }}
  21. .overline.pa-4.grey--text {{ $t('admin:mail.sender') }}
  22. .px-4
  23. v-text-field(
  24. outlined
  25. v-model='config.senderName'
  26. :label='$t(`admin:mail.senderName`)'
  27. required
  28. :counter='255'
  29. prepend-icon='mdi-contact-mail'
  30. )
  31. v-text-field(
  32. outlined
  33. v-model='config.senderEmail'
  34. :label='$t(`admin:mail.senderEmail`)'
  35. required
  36. :counter='255'
  37. prepend-icon='mdi-at'
  38. )
  39. v-divider
  40. .overline.pa-4.grey--text {{ $t('admin:mail.smtp') }}
  41. .px-4
  42. v-text-field(
  43. outlined
  44. v-model='config.host'
  45. :label='$t(`admin:mail.smtpHost`)'
  46. required
  47. :counter='255'
  48. prepend-icon='mdi-memory'
  49. )
  50. v-text-field(
  51. outlined
  52. v-model='config.port'
  53. :label='$t(`admin:mail.smtpPort`)'
  54. required
  55. prepend-icon='mdi-serial-port'
  56. persistent-hint
  57. :hint='$t(`admin:mail.smtpPortHint`)'
  58. style='max-width: 300px;'
  59. )
  60. v-switch(
  61. v-model='config.secure'
  62. :label='$t(`admin:mail.smtpTLS`)'
  63. color='primary'
  64. persistent-hint
  65. :hint='$t(`admin:mail.smtpTLSHint`)'
  66. prepend-icon='mdi-security-network'
  67. inset
  68. )
  69. v-text-field.mt-3(
  70. outlined
  71. v-model='config.user'
  72. :label='$t(`admin:mail.smtpUser`)'
  73. required
  74. :counter='255'
  75. prepend-icon='mdi-shield-account-outline'
  76. )
  77. v-text-field(
  78. outlined
  79. v-model='config.pass'
  80. :label='$t(`admin:mail.smtpPwd`)'
  81. required
  82. prepend-icon='mdi-textbox-password'
  83. type='password'
  84. )
  85. v-flex(lg6 xs12)
  86. v-card.animated.fadeInUp.wait-p2s
  87. v-form
  88. v-toolbar(color='primary', dark, dense, flat)
  89. v-toolbar-title.subtitle-1 {{ $t('admin:mail.dkim') }}
  90. .pa-4
  91. .body-2.grey--text.text--darken-2 {{ $t('admin:mail.dkimHint') }}
  92. v-switch(
  93. v-model='config.useDKIM'
  94. :label='$t(`admin:mail.dkimUse`)'
  95. color='primary'
  96. prepend-icon='mdi-key'
  97. inset
  98. )
  99. v-text-field(
  100. outlined
  101. v-model='config.dkimDomainName'
  102. :label='$t(`admin:mail.dkimDomainName`)'
  103. :counter='255'
  104. prepend-icon='mdi-key'
  105. :disabled='!config.useDKIM'
  106. )
  107. v-text-field(
  108. outlined
  109. v-model='config.dkimKeySelector'
  110. :label='$t(`admin:mail.dkimKeySelector`)'
  111. :counter='255'
  112. prepend-icon='mdi-key'
  113. :disabled='!config.useDKIM'
  114. )
  115. v-textarea(
  116. outlined
  117. v-model='config.dkimPrivateKey'
  118. :label='$t(`admin:mail.dkimPrivateKey`)'
  119. prepend-icon='mdi-key'
  120. persistent-hint
  121. :hint='$t(`admin:mail.dkimPrivateKeyHint`)'
  122. :disabled='!config.useDKIM'
  123. )
  124. v-card.mt-3.animated.fadeInUp.wait-p3s
  125. v-form
  126. v-toolbar(color='teal', dark, dense, flat)
  127. v-toolbar-title.subtitle-1 {{ $t('admin:mail.test') }}
  128. .pa-4
  129. .body-2.grey--text.text--darken-2 {{ $t('admin:mail.testHint') }}
  130. v-text-field.mt-3(
  131. outlined
  132. v-model='testEmail'
  133. :label='$t(`admin:mail.testRecipient`)'
  134. :counter='255'
  135. prepend-icon='mdi-email-outline'
  136. :disabled='testLoading'
  137. )
  138. v-card-chin
  139. v-spacer
  140. v-btn.px-4(color='teal', dark, @click='sendTest', :loading='testLoading')
  141. v-icon(left) mdi-send
  142. span {{ $t('admin:mail.testSend') }}
  143. </template>
  144. <script>
  145. import _ from 'lodash'
  146. import { get } from 'vuex-pathify'
  147. import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
  148. import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'
  149. import mailTestMutation from 'gql/admin/mail/mail-mutation-sendtest.gql'
  150. export default {
  151. data() {
  152. return {
  153. config: {
  154. senderName: '',
  155. senderEmail: '',
  156. host: '',
  157. port: 0,
  158. secure: false,
  159. user: '',
  160. pass: '',
  161. useDKIM: false,
  162. dkimDomainName: '',
  163. dkimKeySelector: '',
  164. dkimPrivateKey: ''
  165. },
  166. testEmail: '',
  167. testLoading: false
  168. }
  169. },
  170. computed: {
  171. darkMode: get('site/dark')
  172. },
  173. methods: {
  174. async save () {
  175. try {
  176. await this.$apollo.mutate({
  177. mutation: mailUpdateConfigMutation,
  178. variables: {
  179. senderName: this.config.senderName || '',
  180. senderEmail: this.config.senderEmail || '',
  181. host: this.config.host || '',
  182. port: _.toSafeInteger(this.config.port) || 0,
  183. secure: this.config.secure || false,
  184. user: this.config.user || '',
  185. pass: this.config.pass || '',
  186. useDKIM: this.config.useDKIM || false,
  187. dkimDomainName: this.config.dkimDomainName || '',
  188. dkimKeySelector: this.config.dkimKeySelector || '',
  189. dkimPrivateKey: this.config.dkimPrivateKey || ''
  190. },
  191. watchLoading (isLoading) {
  192. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-update')
  193. }
  194. })
  195. this.$store.commit('showNotification', {
  196. style: 'success',
  197. message: this.$t('admin:mail.saveSuccess'),
  198. icon: 'check'
  199. })
  200. } catch (err) {
  201. this.$store.commit('pushGraphError', err)
  202. }
  203. },
  204. async sendTest () {
  205. try {
  206. const resp = await this.$apollo.mutate({
  207. mutation: mailTestMutation,
  208. variables: {
  209. recipientEmail: this.testEmail
  210. },
  211. watchLoading (isLoading) {
  212. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-test')
  213. }
  214. })
  215. if (!_.get(resp, 'data.mail.sendTest.responseResult.succeeded', false)) {
  216. throw new Error(_.get(resp, 'data.mail.sendTest.responseResult.message', 'An unexpected error occured.'))
  217. }
  218. this.testEmail = ''
  219. this.$store.commit('showNotification', {
  220. style: 'success',
  221. message: this.$t('admin:mail.sendTestSuccess'),
  222. icon: 'check'
  223. })
  224. } catch (err) {
  225. this.$store.commit('pushGraphError', err)
  226. }
  227. }
  228. },
  229. apollo: {
  230. config: {
  231. query: mailConfigQuery,
  232. fetchPolicy: 'network-only',
  233. update: (data) => _.cloneDeep(data.mail.config),
  234. watchLoading (isLoading) {
  235. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-refresh')
  236. }
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang='scss'>
  242. </style>