summary refs log tree commit diff
path: root/nixos/modules/programs/ssmtp.nix
blob: 904989d57a095f101a6bcd88f786c088d43ee541 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Configuration for `ssmtp', a trivial mail transfer agent that can
# replace sendmail/postfix on simple systems.  It delivers email
# directly to an SMTP server defined in its configuration file, wihout
# queueing mail locally.

{ config, pkgs, ... }:

with pkgs.lib;

let

  cfg = config.networking.defaultMailServer;

in

{

  options = {

    networking.defaultMailServer = {

      directDelivery = mkOption {
        default = false;
        example = true;
        description = ''
          Use the trivial Mail Transfer Agent (MTA)
          <command>ssmtp</command> package to allow programs to send
          e-mail.  If you don't want to run a “real” MTA like
          <command>sendmail</command> or <command>postfix</command> on
          your machine, set this option to <literal>true</literal>, and
          set the option
          <option>networking.defaultMailServer.hostName</option> to the
          host name of your preferred mail server.
        '';
      };

      hostName = mkOption {
        example = "mail.example.org";
        description = ''
          The host name of the default mail server to use to deliver
          e-mail.
        '';
      };

      domain = mkOption {
        default = "";
        example = "example.org";
        description = ''
          The domain from which mail will appear to be sent.
        '';
      };

      useTLS = mkOption {
        default = false;
        example = true;
        description = ''
          Whether TLS should be used to connect to the default mail
          server.
        '';
      };

      useSTARTTLS = mkOption {
        default = false;
        example = true;
        description = ''
          Whether the STARTTLS should be used to connect to the default
          mail server.  (This is needed for TLS-capable mail servers
          running on the default SMTP port 25.)
        '';
      };

      authUser = mkOption {
        default = "";
        example = "foo@example.org";
        description = ''
          Username used for SMTP auth. Leave blank to disable.
        '';
      };

      authPass = mkOption {
        default = "";
        example = "correctHorseBatteryStaple";
        description = ''
          Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)
        '';
      };

    };

  };


  config = mkIf cfg.directDelivery {

    environment.etc."ssmtp/ssmtp.conf".text =
      ''
        MailHub=${cfg.hostName}
        FromLineOverride=YES
        ${if cfg.domain != "" then "rewriteDomain=${cfg.domain}" else ""}
        UseTLS=${if cfg.useTLS then "YES" else "NO"}
        UseSTARTTLS=${if cfg.useSTARTTLS then "YES" else "NO"}
        #Debug=YES
        ${if cfg.authUser != "" then "AuthUser=${cfg.authUser}" else ""}
        ${if cfg.authPass != "" then "AuthPass=${cfg.authPass}" else ""}
      '';

    environment.systemPackages = [pkgs.ssmtp];

  };

}