MSMTP

{
  config,
  lib,
  ...
}: let
  cfg = config.dr460nixed.smtp;
in {
  options.dr460nixed.smtp = with lib; {
    enable =
      mkOption
      {
        default = false;
        type = types.bool;
        description = mdDoc ''
          Enable sending mails via CMD using msmtp.
        '';
      };
  };

  config = lib.mkIf cfg.enable {
    programs.msmtp = {
      enable = true;
      setSendmail = true;
      defaults = {
        aliases = "/etc/aliases";
        auth = "login";
        port = 465;
        tls = "on";
        tls_starttls = "off";
        tls_trust_file = "/etc/ssl/certs/ca-certificates.crt";
      };
      accounts = {
        default = {
          from = "[email protected]";
          host = "mail.garudalinux.net";
          passwordeval = "cat /run/secrets/passwords/[email protected]";
          user = "[email protected]";
        };
      };
    };
    environment.etc = {
      "aliases".text = ''
        root: [email protected]
      '';
    };
  };
}