2
0

admin-mail.vue 9.4 KB

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