User Tools

Site Tools


ssh_sendmail_instead_of_login_shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ssh_sendmail_instead_of_login_shell [2022/11/12 01:56] – formatted code block jquahssh_sendmail_instead_of_login_shell [2022/11/13 23:41] (current) – delete --- to be recreated with a more accurate name jquah
Line 1: Line 1:
-==== SSH session that runs sendmail instead of your login shell ==== 
  
-=== What? === 
-A wrapper for your local mail transfer agent (MTA) that initiates an SSH session when your SDF email address appears in the "From:" header. 
- 
-=== 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 "From" header and your ISP's IP block, but the low volume of your outgoing mail cannot justify the cost of a VPM/VHOST/MetaARPA membership. 
- 
-=== 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, if you have not already done so. This step can be omitted if you prefer to type your password for each outgoing mail. 
-  - 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, and of course change all email addresses to the ones you actually want to wrap. 
-  - Configure your mail user agent (MUA) to call the wrapper script, rather than calling your MTA directly. 
- 
-<code> 
-#!/usr/bin/env bash 
-# 
-# msmtp.wrap - bypass local in favor of remote sendmail, 
-#              if certain headers are found 
- 
-Account0=me@sdf.org 
-Account1=me@other-pubnix.net 
-MTA=msmtp 
-draft="$(mktemp -t sendmail.XXXXXX)" 
-cat /dev/stdin > "$draft" 
-sender="$(grep '^From:' "$draft" | head -n 1 | cut -d: -f2)" 
- 
-case "$sender" in 
-    *me@sdf.org* ) 
-        sendmail="ssh $Account0 sendmail -t" ;; 
-    *me@other-pubnix.net* ) 
-        sendmail="ssh $Account1 sendmail -t" ;; 
-    * ) 
-        sendmail="$MTA $*" ;; 
-esac 
- 
-< "$draft" $sendmail; status=$? 
-rm -f "$draft"; exit $status 
-</code> 
ssh_sendmail_instead_of_login_shell.1668218214.txt.gz · Last modified: 2022/11/12 01:56 by jquah