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.

73 lines
2.0 KiB

  1. const _ = require('lodash')
  2. const graphHelper = require('../../helpers/graph')
  3. /* global WIKI */
  4. module.exports = {
  5. Query: {
  6. async mail() { return {} }
  7. },
  8. Mutation: {
  9. async mail() { return {} }
  10. },
  11. MailQuery: {
  12. async config(obj, args, context, info) {
  13. return {
  14. ...WIKI.config.mail,
  15. pass: WIKI.config.mail.pass.length > 0 ? '********' : ''
  16. }
  17. }
  18. },
  19. MailMutation: {
  20. async sendTest(obj, args, context) {
  21. try {
  22. if (_.isEmpty(args.recipientEmail) || args.recipientEmail.length < 6) {
  23. throw new WIKI.Error.MailInvalidRecipient()
  24. }
  25. await WIKI.mail.send({
  26. template: 'test',
  27. to: args.recipientEmail,
  28. subject: 'A test email from your wiki',
  29. text: 'This is a test email sent from your wiki.',
  30. data: {
  31. preheadertext: 'This is a test email sent from your wiki.'
  32. }
  33. })
  34. return {
  35. responseResult: graphHelper.generateSuccess('Test email sent successfully.')
  36. }
  37. } catch (err) {
  38. return graphHelper.generateError(err)
  39. }
  40. },
  41. async updateConfig(obj, args, context) {
  42. try {
  43. WIKI.config.mail = {
  44. senderName: args.senderName,
  45. senderEmail: args.senderEmail,
  46. host: args.host,
  47. port: args.port,
  48. secure: args.secure,
  49. verifySSL: args.verifySSL,
  50. user: args.user,
  51. pass: (args.pass === '********') ? WIKI.config.mail.pass : args.pass,
  52. useDKIM: args.useDKIM,
  53. dkimDomainName: args.dkimDomainName,
  54. dkimKeySelector: args.dkimKeySelector,
  55. dkimPrivateKey: args.dkimPrivateKey
  56. }
  57. await WIKI.configSvc.saveToDb(['mail'])
  58. WIKI.mail.init()
  59. return {
  60. responseResult: graphHelper.generateSuccess('Mail configuration updated successfully.')
  61. }
  62. } catch (err) {
  63. return graphHelper.generateError(err)
  64. }
  65. }
  66. }
  67. }