Netcat is really a cleaner solution from this perspective.
Netcat, combined with the openssl utility, can do some amazing things with moving files over SMTP. I can post my favorite hand-rolled script if there is interest. I boiled it out of mpack down to the shell.
Socat doesn't support STARTTLS. If you want to debug SMTP submission "openssl s_client -starttls smtp -connect server:587" is awesome. Just take care not to use upper case "R" or "Q". Man, why did they implement rekeying and quit in such a bothersome way. Just use recipient and quit instead of RECIPIENT and QUIT.
Here is the script. This is like FTP/scp to an inbox. Remove the two leading spaces that HN needs in quoting code blocks.
This uses OpenSSL to a) send a base64-encoded MD5 hash of each file in the headers, then b) base64-encode the file itself. There is also an OpenSSL "smime" applet, but I really don't know what it does.
The netcat is going to send this over cleartext; use OpenSSL s_client (or maybe "nc -ssl" if your netcat supports it) if cleartext is a problem.
This is written in dash, so it should run in most POSIX-compliant shells. Note that local variables are not POSIX-compliant; for a true POSIX shell, change the shell function to "mimer () ( ...body ...)" to force a subshell.
Shellcheck doesn't like printf formats done like this, but you can't please everybody.
This also works in Windows with ports of OpenSSL and busybox, btw.
$ cat mimer
#!/bin/dash
mimer () {
local f \
SMTP='smtp.yourco.com' \
BOUND="$(openssl rand -base64 21 | sed 's@[/+=]@_@g')" \
SFORMAT='helo %s
mail from:%s
rcpt to:%s
data
Mime-Version: 1.0
Subject: %s
Content-Type: multipart/mixed; boundary="%s"
This is a MIME encoded message.
' \
MFORMAT='%s
Content-Type: application/octet-stream; name="%s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="%s"
Content-MD5: %s
'
{
printf "$SFORMAT" "$HOSTNAME" "$2" "$1" "$3" "$BOUND"
shift 3
while [ -n "$1" ]
do f=${1##*/}
printf "$MFORMAT" "--$BOUND" "$f" "$f" \
"$(openssl dgst -md5 -binary < "$1" | openssl base64)"
# base64 < "$1"
openssl base64 -in "$1"
echo
shift
done
printf '%s--\n.\nquit\n' "--$BOUND"
} | sed -e 's/$/\r/' | nc "$SMTP" 25
}
[ -z "$4" ] && { echo mimer to from subject file1 '[file2]' ...; exit; }
mimer "$@"
Netcat, combined with the openssl utility, can do some amazing things with moving files over SMTP. I can post my favorite hand-rolled script if there is interest. I boiled it out of mpack down to the shell.