adminMail.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  2. import {Button} from 'sentry/components/button';
  3. import {t} from 'sentry/locale';
  4. import {useApiQuery, useMutation} from 'sentry/utils/queryClient';
  5. import useApi from 'sentry/utils/useApi';
  6. type MailData = {
  7. mailFrom: string;
  8. mailHost: string;
  9. mailListNamespace: string;
  10. mailPassword: string;
  11. mailPort: string;
  12. mailUseSsl: string;
  13. mailUseTls: string;
  14. mailUsername: string;
  15. testMailEmail: string;
  16. };
  17. export default function AdminMail() {
  18. const api = useApi();
  19. const {data, isLoading} = useApiQuery<MailData>(['/internal/mail/'], {staleTime: 0});
  20. const {mutate: sendTestEmail} = useMutation({
  21. mutationFn: () => api.requestPromise('/internal/mail/', {method: 'POST'}),
  22. onSuccess: () => {
  23. addSuccessMessage(t('A test email has been sent to %s', testMailEmail));
  24. },
  25. onError: () => {
  26. addErrorMessage(t('Unable to send test email. Check your server logs'));
  27. },
  28. });
  29. if (isLoading || !data) {
  30. return null;
  31. }
  32. const {
  33. mailFrom,
  34. mailHost,
  35. mailPort,
  36. mailUsername,
  37. mailPassword,
  38. mailUseTls,
  39. mailUseSsl,
  40. mailListNamespace,
  41. testMailEmail,
  42. } = data;
  43. return (
  44. <div>
  45. <h3>{t('SMTP Settings')}</h3>
  46. <dl className="vars">
  47. <dt>{t('From Address')}</dt>
  48. <dd>
  49. <pre className="val">{mailFrom}</pre>
  50. </dd>
  51. <dt>{t('Host')}</dt>
  52. <dd>
  53. <pre className="val">
  54. {mailHost}:{mailPort}
  55. </pre>
  56. </dd>
  57. <dt>{t('Username')}</dt>
  58. <dd>
  59. <pre className="val">{mailUsername || <em>{t('not set')}</em>}</pre>
  60. </dd>
  61. <dt>{t('Password')}</dt>
  62. <dd>
  63. <pre className="val">{mailPassword ? '********' : <em>{t('not set')}</em>}</pre>
  64. </dd>
  65. <dt>{t('STARTTLS?')}</dt>
  66. <dd>
  67. <pre className="val">{mailUseTls ? t('Yes') : t('No')}</pre>
  68. </dd>
  69. <dt>{t('SSL?')}</dt>
  70. <dd>
  71. <pre className="val">{mailUseSsl ? t('Yes') : t('No')}</pre>
  72. </dd>
  73. <dt>{t('Mailing List Namespace')}</dt>
  74. <dd>
  75. <pre className="val">{mailListNamespace}</pre>
  76. </dd>
  77. </dl>
  78. <h3>{t('Test Settings')}</h3>
  79. <p>
  80. {t(
  81. "Send an email to your account's email address to confirm that everything is configured correctly."
  82. )}
  83. </p>
  84. <Button onClick={() => sendTestEmail()}>
  85. {t('Send a test email to %s', testMailEmail)}
  86. </Button>
  87. </div>
  88. );
  89. }