adminMail.tsx 2.8 KB

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