adminMail.tsx 2.8 KB

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