Msmtp: Difference between revisions

imported>Onny
mNo edit summary
Tie-ling (talk | contribs)
Configuration: merged from zfs article
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[https://marlam.de/msmtp/ msmtp] is a basic email sender client. It is easy to configure but lacks some features like queuing when offline.
[https://marlam.de/msmtp/ msmtp] is an easy to configure basic email sender client with fairly complete sendmail compatibility.


== Installation ==
== Installation ==
Line 24: Line 24:


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# sendmail john.doe@mail.com
# echo -e "Content-Type: text/plain\r\nSubject: Test\r\n\r\nHello World" | sendmail john.doe@mail.com
Subject: Test Send Mail
Hello World
control d (this key combination of control key and d will finish the email.)
</syntaxhighlight>
</syntaxhighlight>


A mail with the subject ''Test Send Mail'' will be send to the recipient ''john.doe@mail.com'' including the body text ''Hello World''.
A mail with the subject ''Test'' will be sent to the recipient ''john.doe@mail.com'' including the body text ''Hello World''. A Mime-Header is added to the mail content for better compatibility.


== Configuration ==
== Configuration ==
Line 39: Line 36:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.msmtp = {
{
   enable = true;
  age.secrets.msmtp = {
   accounts = {
    file = "${inputs.self.outPath}/secrets/msmtp.age";
     default = {
   };
       auth = true;
 
       tls = true;
  # for zed enableMail, enable sendmailSetuidWrapper
       from = "<from address here>";
  services.mail.sendmailSetuidWrapper.enable = true;
       host = "<hostname here>";
 
       user = "<username here>";
   programs.msmtp = {
       passwordeval = "cat /secrets/smtp_password.txt";
     enable = true;
    setSendmail = true;
    defaults = {
       aliases = "/etc/aliases";
       port = 587;
       auth = "plain";
       tls = "on";
       tls_starttls = "on";
    };
    accounts = {
       default = {
        host = "smtp.mail.example.com";
        passwordeval = "cat ${config.age.secrets.msmtp.path}";
        user = "myname@example.com";
        from = "myname@example.com";
      };
     };
     };
   };
   };
};
}
</syntaxhighlight>
</syntaxhighlight>


Line 58: Line 70:
=== Aliases ===
=== Aliases ===


Example:
Then, configure an alias for root account. With this alias configured, all mails sent to root, such as cron job results and failed sudo login events, will be redirected to the configured email account.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.msmtp.defaults = {
{
   aliases = "/etc/aliases";
   environment.etc.aliases.text = ''
};
    root: admin@example.com
 
  '';
environment.etc = {
}
  "aliases" = {
    text = ''
      root: me@example.com
    '';
    mode = "0644";
  };
};
</syntaxhighlight>
</syntaxhighlight>