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.

72 lines
1.9 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. user: args.user,
  50. pass: (args.pass === '********') ? WIKI.config.mail.pass : args.pass,
  51. useDKIM: args.useDKIM,
  52. dkimDomainName: args.dkimDomainName,
  53. dkimKeySelector: args.dkimKeySelector,
  54. dkimPrivateKey: args.dkimPrivateKey
  55. }
  56. await WIKI.configSvc.saveToDb(['mail'])
  57. WIKI.mail.init()
  58. return {
  59. responseResult: graphHelper.generateSuccess('Mail configuration updated successfully.')
  60. }
  61. } catch (err) {
  62. return graphHelper.generateError(err)
  63. }
  64. }
  65. }
  66. }