ssh_noninteractive_sendmail
Differences
This shows you the differences between two versions of the page.
ssh_noninteractive_sendmail [2022/11/13 23:44] – created jquah | ssh_noninteractive_sendmail [2022/11/26 22:55] (current) – slight changes to the case pattern matching jquah | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== SSH session that runs sendmail instead of an interactive shell ==== | ||
+ | |||
+ | === What? === | ||
+ | A wrapper for your local mail transfer agent (MTA) that initiates an SSH session when your SDF email address appears in the " | ||
+ | |||
+ | === Why? === | ||
+ | You want to send email from your SDF address without running the risk that the receiving server will reject it due to a mismatch between the " | ||
+ | |||
+ | * the low volume of your outgoing mail cannot justify the cost of a VPM/ | ||
+ | * your Internet connection has too high a latency to be running a full-screen editor within an SSH session. | ||
+ | |||
+ | === Where? === | ||
+ | a *BSD, Linux, or WSL environment with a client that generates MIME-formatted mail (as expected by sendmail-compatible MTAs such as msmtp) | ||
+ | |||
+ | === How? === | ||
+ | - Set up [[ssh public key authentication|SSH public key authentication]], | ||
+ | - Save the wrapper script below somewhere in your $PATH. Change the value of $MTA to the mail transport agent that you would otherwise be using for outgoing mail, the value of $PATH if any of the commands live in non-standard locations, and of course all the hard-coded email addresses in the script. | ||
+ | - Configure your mail user agent (MUA) to call the wrapper script, rather than calling your MTA directly. | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # | ||
+ | # msmtp.wrap - bypass local in favor of remote sendmail, | ||
+ | # if certain headers are found | ||
+ | |||
+ | PATH=/ | ||
+ | Account0=me@sdf.org | ||
+ | Account1=me@other-pubnix.net | ||
+ | MTA=msmtp | ||
+ | draft=" | ||
+ | cat /dev/stdin > " | ||
+ | sender=" | ||
+ | |||
+ | case " | ||
+ | *$Account0*) | ||
+ | sendmail=" | ||
+ | *$Account1*) | ||
+ | sendmail=" | ||
+ | *) | ||
+ | sendmail=" | ||
+ | esac | ||
+ | |||
+ | < " | ||
+ | rm -f " | ||
+ | </ | ||
+ | |||
+ | === What Next? === | ||
+ | |||
+ | The possibilities for customization of this wrapper are only limited by your imagination. You can parse the outgoing messages to look for particular recipients, subject lines, etc., and define a custom $sendmail command to handle each case. On the SDF side, the arguments following '' | ||