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.

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