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.

258 lines
9.4 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='/_assets/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-mailbox'
  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-mailbox'
  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-switch(
  70. v-model='config.verifySSL'
  71. :label='$t(`admin:mail.smtpVerifySSL`)'
  72. color='primary'
  73. persistent-hint
  74. :hint='$t(`admin:mail.smtpVerifySSLHint`)'
  75. prepend-icon='mdi-security-network'
  76. inset
  77. )
  78. v-text-field.mt-8(
  79. outlined
  80. v-model='config.user'
  81. :label='$t(`admin:mail.smtpUser`)'
  82. required
  83. :counter='255'
  84. prepend-icon='mdi-shield-account-outline'
  85. )
  86. v-text-field(
  87. outlined
  88. v-model='config.pass'
  89. :label='$t(`admin:mail.smtpPwd`)'
  90. required
  91. prepend-icon='mdi-form-textbox-password'
  92. type='password'
  93. )
  94. v-flex(lg6 xs12)
  95. v-card.animated.fadeInUp.wait-p2s
  96. v-form
  97. v-toolbar(color='primary', dark, dense, flat)
  98. v-toolbar-title.subtitle-1 {{ $t('admin:mail.dkim') }}
  99. v-card-info
  100. span {{ $t('admin:mail.dkimHint') }}
  101. .pa-4
  102. v-switch(
  103. v-model='config.useDKIM'
  104. :label='$t(`admin:mail.dkimUse`)'
  105. color='primary'
  106. prepend-icon='mdi-key'
  107. inset
  108. )
  109. v-text-field(
  110. outlined
  111. v-model='config.dkimDomainName'
  112. :label='$t(`admin:mail.dkimDomainName`)'
  113. :counter='255'
  114. prepend-icon='mdi-key'
  115. :disabled='!config.useDKIM'
  116. )
  117. v-text-field(
  118. outlined
  119. v-model='config.dkimKeySelector'
  120. :label='$t(`admin:mail.dkimKeySelector`)'
  121. :counter='255'
  122. prepend-icon='mdi-key'
  123. :disabled='!config.useDKIM'
  124. )
  125. v-textarea(
  126. outlined
  127. v-model='config.dkimPrivateKey'
  128. :label='$t(`admin:mail.dkimPrivateKey`)'
  129. prepend-icon='mdi-key'
  130. persistent-hint
  131. :hint='$t(`admin:mail.dkimPrivateKeyHint`)'
  132. :disabled='!config.useDKIM'
  133. )
  134. v-card.mt-3.animated.fadeInUp.wait-p3s
  135. v-form
  136. v-toolbar(color='teal', dark, dense, flat)
  137. v-toolbar-title.subtitle-1 {{ $t('admin:mail.test') }}
  138. .pa-4
  139. .body-2.grey--text.text--darken-2 {{ $t('admin:mail.testHint') }}
  140. v-text-field.mt-3(
  141. outlined
  142. v-model='testEmail'
  143. :label='$t(`admin:mail.testRecipient`)'
  144. :counter='255'
  145. prepend-icon='mdi-email-outline'
  146. :disabled='testLoading'
  147. )
  148. v-card-chin
  149. v-spacer
  150. v-btn.px-4(color='teal', dark, @click='sendTest', :loading='testLoading')
  151. v-icon(left) mdi-send
  152. span {{ $t('admin:mail.testSend') }}
  153. </template>
  154. <script>
  155. import _ from 'lodash'
  156. import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
  157. import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'
  158. import mailTestMutation from 'gql/admin/mail/mail-mutation-sendtest.gql'
  159. export default {
  160. data() {
  161. return {
  162. config: {
  163. senderName: '',
  164. senderEmail: '',
  165. host: '',
  166. port: 0,
  167. secure: false,
  168. verifySSL: false,
  169. user: '',
  170. pass: '',
  171. useDKIM: false,
  172. dkimDomainName: '',
  173. dkimKeySelector: '',
  174. dkimPrivateKey: ''
  175. },
  176. testEmail: '',
  177. testLoading: false
  178. }
  179. },
  180. methods: {
  181. async save () {
  182. try {
  183. await this.$apollo.mutate({
  184. mutation: mailUpdateConfigMutation,
  185. variables: {
  186. senderName: this.config.senderName || '',
  187. senderEmail: this.config.senderEmail || '',
  188. host: this.config.host || '',
  189. port: _.toSafeInteger(this.config.port) || 0,
  190. secure: this.config.secure || false,
  191. verifySSL: this.config.verifySSL || false,
  192. user: this.config.user || '',
  193. pass: this.config.pass || '',
  194. useDKIM: this.config.useDKIM || false,
  195. dkimDomainName: this.config.dkimDomainName || '',
  196. dkimKeySelector: this.config.dkimKeySelector || '',
  197. dkimPrivateKey: this.config.dkimPrivateKey || ''
  198. },
  199. watchLoading (isLoading) {
  200. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-update')
  201. }
  202. })
  203. this.$store.commit('showNotification', {
  204. style: 'success',
  205. message: this.$t('admin:mail.saveSuccess'),
  206. icon: 'check'
  207. })
  208. } catch (err) {
  209. this.$store.commit('pushGraphError', err)
  210. }
  211. },
  212. async sendTest () {
  213. try {
  214. const resp = await this.$apollo.mutate({
  215. mutation: mailTestMutation,
  216. variables: {
  217. recipientEmail: this.testEmail
  218. },
  219. watchLoading (isLoading) {
  220. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-test')
  221. }
  222. })
  223. if (!_.get(resp, 'data.mail.sendTest.responseResult.succeeded', false)) {
  224. throw new Error(_.get(resp, 'data.mail.sendTest.responseResult.message', 'An unexpected error occurred.'))
  225. }
  226. this.testEmail = ''
  227. this.$store.commit('showNotification', {
  228. style: 'success',
  229. message: this.$t('admin:mail.sendTestSuccess'),
  230. icon: 'check'
  231. })
  232. } catch (err) {
  233. this.$store.commit('pushGraphError', err)
  234. }
  235. }
  236. },
  237. apollo: {
  238. config: {
  239. query: mailConfigQuery,
  240. fetchPolicy: 'network-only',
  241. update: (data) => _.cloneDeep(data.mail.config),
  242. watchLoading (isLoading) {
  243. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-refresh')
  244. }
  245. }
  246. }
  247. }
  248. </script>
  249. <style lang='scss'>
  250. </style>