admin-mail.vue 8.9 KB

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