admin-mail.vue 8.8 KB

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