{
  config,
  lib,
  sec,
  ...
}:
let
  inherit (config.machine.synapse)
    enable
    domain
    ;
  address = "noreply@${domain}";
in
with lib;
mkIf (enable && config.machine.mail.enable) {
  services.matrix-synapse = {
    settings = {
      admin_contact = address;
      registrations_require_3pid = [ "email" ];
      email = {
        smtp_host = config.machine.mail.fqdn;
        smtp_port = 465;
        smtp_user = address;
        require_transport_security = true;
        enable_tls = true;
        notif_from = "RuJect Matrix <${address}>";
        app_name = "RuJect Matrix";
      };
    };
  };

  mailserver = {
    domains = [ domain ];
    accounts.${address} = {
      hashedPasswordFile = sec."mail/serviceHashedPassword".path;
      aliases = [ ];
      sendOnly = true;
    };
  };
}
